Deduplicate mentions
This commit is contained in:
parent
a48ee148ae
commit
f1333cb131
|
@ -45,16 +45,27 @@ function toAccount(event: Event<0>) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function toMention(tag: string[]) {
|
async function toMention(pubkey: string) {
|
||||||
const profile = await getAuthor(tag[1]);
|
const profile = await getAuthor(pubkey);
|
||||||
const account = profile ? toAccount(profile) : undefined;
|
const account = profile ? toAccount(profile) : undefined;
|
||||||
|
|
||||||
return {
|
if (account) {
|
||||||
id: account?.id || tag[1],
|
return {
|
||||||
acct: account?.acct || tag[1],
|
id: account.id,
|
||||||
username: account?.username || tag[1],
|
acct: account.acct,
|
||||||
url: account?.url,
|
username: account.username,
|
||||||
};
|
url: account.url,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const { origin } = new URL(LOCAL_DOMAIN);
|
||||||
|
const npub = nip19.npubEncode(pubkey);
|
||||||
|
return {
|
||||||
|
id: pubkey,
|
||||||
|
acct: npub,
|
||||||
|
username: npub,
|
||||||
|
url: `${origin}/users/${pubkey}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function toStatus(event: Event<1>) {
|
async function toStatus(event: Event<1>) {
|
||||||
|
@ -65,6 +76,14 @@ async function toStatus(event: Event<1>) {
|
||||||
const inReplyTo = event.tags
|
const inReplyTo = event.tags
|
||||||
.find((tag) => tag[0] === 'e' && (!tag[3] || tag[3] === 'reply' || tag[3] === 'root'));
|
.find((tag) => tag[0] === 'e' && (!tag[3] || tag[3] === 'reply' || tag[3] === 'root'));
|
||||||
|
|
||||||
|
const mentionedPubkeys = [
|
||||||
|
...new Set(
|
||||||
|
event.tags
|
||||||
|
.filter((tag) => tag[0] === 'p')
|
||||||
|
.map((tag) => tag[1]),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
account,
|
account,
|
||||||
|
@ -86,7 +105,7 @@ async function toStatus(event: Event<1>) {
|
||||||
reblog: null,
|
reblog: null,
|
||||||
application: null,
|
application: null,
|
||||||
media_attachments: [],
|
media_attachments: [],
|
||||||
mentions: await Promise.all(event.tags.filter((tag) => tag[0] === 'p').map(toMention)),
|
mentions: await Promise.all(mentionedPubkeys.map(toMention)),
|
||||||
tags: [],
|
tags: [],
|
||||||
emojis: [],
|
emojis: [],
|
||||||
card: null,
|
card: null,
|
||||||
|
|
Loading…
Reference in New Issue