From 3b85491ee4de257f9775600238aff4cdbec73231 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 24 Oct 2023 18:29:14 +0200 Subject: [PATCH] [backend] Don't recursively resolve user profile mentions --- .../backend/src/remote/activitypub/models/person.ts | 3 ++- packages/backend/src/remote/resolve-user.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index 1fb0f52cd..fdbc58c71 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -170,6 +170,7 @@ export async function createPerson( uri: string, resolver?: Resolver, subjectHost?: string, + skipMentions: boolean = false ): Promise { if (typeof uri !== "string") throw new Error("uri is not string"); @@ -399,7 +400,7 @@ export async function createPerson( updateUsertags(user!, tags); // Mentions update - UserProfiles.updateMentions(user!.id); + if (!skipMentions) UserProfiles.updateMentions(user!.id); //#region Fetch avatar and header image const [avatar, banner] = await Promise.all( diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index 96c83023f..1778ba3c8 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -30,7 +30,8 @@ export async function resolveUser( username: string, host: string | null, refresh: boolean = true, - awaitRefresh: boolean = true + awaitRefresh: boolean = true, + skipMentionsOnCreate: boolean = false ): Promise { const usernameLower = username.toLowerCase(); @@ -104,14 +105,14 @@ export async function resolveUser( // Otherwise create and return new user else { logger.succ(`return new remote user: ${chalk.magenta(finalAcctLower)}`); - return await createPerson(fingerRes.self.href, undefined, subjectHost); + return await createPerson(fingerRes.self.href, undefined, subjectHost, skipMentionsOnCreate); } } } // Not a split domain setup, so we can simply create and return the new user logger.succ(`return new remote user: ${chalk.magenta(finalAcctLower)}`); - return await createPerson(fingerRes.self.href, undefined, subjectHost); + return await createPerson(fingerRes.self.href, undefined, subjectHost, skipMentionsOnCreate); } // If user information is out of date, return it by starting over from WebFinger @@ -187,7 +188,7 @@ export async function resolveUser( } else if (refresh && !awaitRefresh && (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24)) { // Run the refresh in the background // noinspection ES6MissingAwait - resolveUser(username, host, true, true); + resolveUser(username, host, true, true, skipMentionsOnCreate); } logger.info(`return existing remote user: ${acctLower}`); @@ -197,7 +198,7 @@ export async function resolveUser( export async function resolveMentionToUserAndProfile(username: string, host: string | null, objectHost: string | null) { return profileMentionCache.fetch(`${username}@${host ?? objectHost}`, async () => { try { - const user = await resolveUser(username, host ?? objectHost, false); + const user = await resolveUser(username, host ?? objectHost, false, false, true); const profile = await UserProfiles.findOneBy({ userId: user.id }); const data = { username, host: host ?? objectHost };