[mastodon-client] Fail gracefully if user resolve fails

This commit is contained in:
Laura Hausmann 2023-07-07 18:58:24 +02:00
parent 16df0dd9db
commit acff402e21
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1257,31 +1257,31 @@ export default class Misskey implements MegalodonInterface {
} }
public async getMentions(text: string, cache: AccountCache): Promise<Entity.Mention[]> { public async getMentions(text: string, cache: AccountCache): Promise<Entity.Mention[]> {
console.log(`getting mentions for message: '${text}'`);
const mentions :Entity.Mention[] = []; const mentions :Entity.Mention[] = [];
if (text == undefined) if (text == undefined)
return mentions; return mentions;
console.log('text is not undefined, continuing');
const mentionMatch = text.matchAll(/(?<=^|\s)@(?<user>.*?)(?:@(?<host>.*?)|)(?=\s|$)/g); const mentionMatch = text.matchAll(/(?<=^|\s)@(?<user>.*?)(?:@(?<host>.*?)|)(?=\s|$)/g);
for (const m of mentionMatch) { for (const m of mentionMatch) {
if (m.groups == null) try {
continue; if (m.groups == null)
continue;
const account = await this.getAccountByNameCached(m.groups.user, m.groups.host, cache); const account = await this.getAccountByNameCached(m.groups.user, m.groups.host, cache);
if (account == null) if (account == null)
continue; continue;
mentions.push({ mentions.push({
id: account.id, id: account.id,
url: account.url, url: account.url,
username: account.username, username: account.username,
acct: account.acct acct: account.acct
}); });
}
catch {}
} }
return mentions; return mentions;