[backend] Actually resolve with objectHost

This commit is contained in:
Laura Hausmann 2023-10-14 17:16:21 +02:00
parent 8719a6922e
commit c0d7ecf5c3
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605

View File

@ -179,15 +179,17 @@ export async function resolveUser(
export async function resolveMentionWithFallback(username: string, host: string | null, objectHost: string | null, cache: IMentionedRemoteUsers): Promise<string> { export async function resolveMentionWithFallback(username: string, host: string | null, objectHost: string | null, cache: IMentionedRemoteUsers): Promise<string> {
let fallback = `${config.url}/@${username}`; let fallback = `${config.url}/@${username}`;
if (host !== null) fallback += `@${host}`; if (host !== null && host !== config.domain)
else if (objectHost !== null) fallback += `@${objectHost}`; fallback += `@${host}`;
else if (objectHost !== null && objectHost !== config.domain && host !== config.domain)
fallback += `@${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;
if (host === null || host === config.domain) return fallback; if ((host === null && objectHost === null) || host === config.domain) return fallback;
try { try {
const user = await resolveUser(username, host, false); const user = await resolveUser(username, host ?? objectHost, false);
const profile = await UserProfiles.findOneBy({ userId: user.id }); const profile = await UserProfiles.findOneBy({ userId: user.id });
return profile?.url ?? user.uri ?? fallback; return profile?.url ?? user.uri ?? fallback;
} }