From 9476d14d6c0d2c2d6e28fef2ee737b2ae1c42251 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 13 Jan 2023 01:19:24 +0100 Subject: [PATCH] fix: dedupe accounts in reply mentions --- composables/masto/statusDrafts.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/composables/masto/statusDrafts.ts b/composables/masto/statusDrafts.ts index 2ac23d0d..a8d9a06d 100644 --- a/composables/masto/statusDrafts.ts +++ b/composables/masto/statusDrafts.ts @@ -15,7 +15,6 @@ export function getDefaultDraft(options: Partial@${acct}` +function toMentionsHTML(accounts: string[]) { + return accounts.map(acct => `@${acct}`).join(' ') } function getAccountsToMention(status: mastodon.v1.Status) { const userId = currentUser.value?.account.id - const accountsToMention: string[] = [] + const accountsToMention = new Set() if (status.account.id !== userId) - accountsToMention.push(status.account.acct) - accountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct))) - return accountsToMention + accountsToMention.add(status.account.acct) + status.mentions + .filter(mention => mention.id !== userId) + .map(mention => mention.acct) + .forEach(i => accountsToMention.add(i)) + return Array.from(accountsToMention) } export function getReplyDraft(status: mastodon.v1.Status) { @@ -70,7 +72,7 @@ export function getReplyDraft(status: mastodon.v1.Status) { key: `reply-${status.id}`, draft: () => { return getDefaultDraft({ - initialText: accountsToMention.map(acct => mentionHTML(acct)).join(' '), + initialText: toMentionsHTML(accountsToMention), inReplyToId: status!.id, visibility: status.visibility, })