mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[mastodon-client] Skip invalid mentions
This commit is contained in:
parent
eadf9acdc3
commit
5dcd4c4fff
@ -207,12 +207,13 @@ export function getMentionFallbackUri(username: string, host: string | null, obj
|
||||
return fallback;
|
||||
}
|
||||
|
||||
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, cachedOnly: boolean = false): Promise<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 ?? fallback;
|
||||
if ((host === null && objectHost === null) || host === config.domain) return fallback;
|
||||
if (cachedOnly) return fallback;
|
||||
|
||||
return mentionUriCache.fetch(fallback, async () => {
|
||||
try {
|
||||
|
@ -136,18 +136,27 @@ export class MfmHelpers {
|
||||
},
|
||||
|
||||
async mention(node) {
|
||||
const el = doc.createElement("span");
|
||||
el.setAttribute("class", "h-card");
|
||||
el.setAttribute("translate", "no");
|
||||
const a = doc.createElement("a");
|
||||
const { username, host, acct } = node.props;
|
||||
a.href = await resolveMentionWithFallback(username, host, objectHost, mentionedRemoteUsers);
|
||||
a.className = "u-url mention";
|
||||
const span = doc.createElement("span");
|
||||
span.textContent = username;
|
||||
a.textContent = '@';
|
||||
a.appendChild(span);
|
||||
el.appendChild(a);
|
||||
const fallback = await resolveMentionWithFallback(username, host, objectHost, mentionedRemoteUsers, true);
|
||||
const isLocal = (host === null && objectHost === null) || host === config.domain;
|
||||
const isInvalid = fallback.startsWith(config.url) && !isLocal;
|
||||
|
||||
const el = doc.createElement("span");
|
||||
if (isInvalid) {
|
||||
el.textContent = acct;
|
||||
} else {
|
||||
el.setAttribute("class", "h-card");
|
||||
el.setAttribute("translate", "no");
|
||||
const a = doc.createElement("a");
|
||||
a.href = fallback;
|
||||
a.className = "u-url mention";
|
||||
const span = doc.createElement("span");
|
||||
span.textContent = username;
|
||||
a.textContent = '@';
|
||||
a.appendChild(span);
|
||||
el.appendChild(a);
|
||||
}
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user