[backend] Fix populateMentions remote filter

This commit is contained in:
Laura Hausmann 2023-10-16 01:21:43 +02:00
parent 3cdf9eee94
commit c64f6b6db6
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 4 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import { extractMentions } from "@/misc/extract-mentions.js";
import { resolveMentionToUserAndProfile } from "@/remote/resolve-user.js"; import { resolveMentionToUserAndProfile } from "@/remote/resolve-user.js";
import { IMentionedRemoteUsers } from "@/models/entities/note.js"; import { IMentionedRemoteUsers } from "@/models/entities/note.js";
import { unique } from "@/prelude/array.js"; import { unique } from "@/prelude/array.js";
import config from "@/config/index.js";
export const UserProfileRepository = db.getRepository(UserProfile).extend({ export const UserProfileRepository = db.getRepository(UserProfile).extend({
async updateMentions(id: UserProfile["userId"]){ 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<IMentionedRemoteUsers> { async function populateMentions(tokens: mfm.MfmNode[], objectHost: string | null): Promise<IMentionedRemoteUsers> {
const mentions = extractMentions(tokens); const mentions = extractMentions(tokens);
const resolved = await Promise.all(mentions.map(m => resolveMentionToUserAndProfile(m.username, m.host, objectHost))); 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 => { const res = remote.map(m => {
return { return {
uri: m.user.uri!, uri: m.user.uri!,

View file

@ -211,7 +211,7 @@ export async function resolveMentionWithFallback(username: string, host: string
const fallback = getMentionFallbackUri(username, host, objectHost); const fallback = getMentionFallbackUri(username, host, objectHost);
const cached = cache.find(r => r.username.toLowerCase() === username.toLowerCase() && r.host === host); 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; if ((host === null && objectHost === null) || host === config.domain) return fallback;
return mentionUriCache.fetch(fallback, async () => { return mentionUriCache.fetch(fallback, async () => {