From a9436306abbb504e7746ff5821b6fe2daac1e4fe Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Fri, 9 Nov 2018 11:01:55 +0900 Subject: [PATCH] Fix #3170 (#3173) --- src/prelude/array.ts | 4 ++++ src/remote/activitypub/models/note.ts | 14 ++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/prelude/array.ts b/src/prelude/array.ts index 54f7081712..42f05dc0c9 100644 --- a/src/prelude/array.ts +++ b/src/prelude/array.ts @@ -18,6 +18,10 @@ export function erase(x: T, xs: T[]): T[] { return xs.filter(y => x !== y); } +export function setDifference(xs: T[], ys: T[]): T[] { + return xs.filter(x => !ys.includes(x)); +} + export function unique(xs: T[]): T[] { return [...new Set(xs)]; } diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index f9380eb4f4..ce9a4daf16 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -13,7 +13,7 @@ import htmlToMFM from '../../../mfm/html-to-mfm'; import Emoji from '../../../models/emoji'; import { ITag } from './tag'; import { toUnicode } from 'punycode'; -import { unique } from '../../../prelude/array'; +import { unique, concat, setDifference } from '../../../prelude/array'; const log = debug('misskey:activitypub'); @@ -179,15 +179,9 @@ async function extractEmojis(tags: ITag[], host_: string) { ); } -async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: string[], resolver: Resolver ) { - let uris = [] as string[]; - - if (to) uris.concat(to); - if (cc) uris.concat(cc); - - uris = uris.filter(x => x !== 'https://www.w3.org/ns/activitystreams#Public'); - uris = uris.filter(x => x !== `${actor.uri}/followers`); - uris = unique(uris); +async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: string[], resolver: Resolver) { + const ignoreUris = ['https://www.w3.org/ns/activitystreams#Public', `${actor.uri}/followers`]; + const uris = setDifference(unique(concat([to || [], cc || []])), ignoreUris); const users = await Promise.all( uris.map(async uri => await resolvePerson(uri, null, resolver).catch(() => null))