From c64f6b6db6b8b66a7326701fd1c05bfc33a4d643 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 16 Oct 2023 01:21:43 +0200 Subject: [PATCH] [backend] Fix populateMentions remote filter --- packages/backend/src/models/repositories/user-profile.ts | 4 +++- packages/backend/src/remote/resolve-user.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/models/repositories/user-profile.ts b/packages/backend/src/models/repositories/user-profile.ts index ef540c277..09e28b695 100644 --- a/packages/backend/src/models/repositories/user-profile.ts +++ b/packages/backend/src/models/repositories/user-profile.ts @@ -5,6 +5,7 @@ import { extractMentions } from "@/misc/extract-mentions.js"; import { resolveMentionToUserAndProfile } from "@/remote/resolve-user.js"; import { IMentionedRemoteUsers } from "@/models/entities/note.js"; import { unique } from "@/prelude/array.js"; +import config from "@/config/index.js"; export const UserProfileRepository = db.getRepository(UserProfile).extend({ async updateMentions(id: UserProfile["userId"]){ @@ -28,7 +29,8 @@ export const UserProfileRepository = db.getRepository(UserProfile).extend({ async function populateMentions(tokens: mfm.MfmNode[], objectHost: string | null): Promise { const mentions = extractMentions(tokens); const resolved = await Promise.all(mentions.map(m => resolveMentionToUserAndProfile(m.username, m.host, objectHost))); - const remote = resolved.filter(p => p && p.data.host !== null).map(p => p!); + const remote = resolved.filter(p => p && p.data.host !== config.domain && (p.data.host !== null || objectHost !== null)) + .map(p => p!); const res = remote.map(m => { return { uri: m.user.uri!, diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index 9206dc6bd..8122a7626 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -211,7 +211,7 @@ export async function resolveMentionWithFallback(username: string, host: string const fallback = getMentionFallbackUri(username, host, objectHost); const cached = cache.find(r => r.username.toLowerCase() === username.toLowerCase() && r.host === host); - if (cached) return cached.url ?? cached.uri; + if (cached) return cached.url ?? cached.uri ?? fallback; if ((host === null && objectHost === null) || host === config.domain) return fallback; return mentionUriCache.fetch(fallback, async () => {