1
0
forked from mirror/misskey

Rename: setDifference -> difference (#3177)

* Improve setDifference

* Rename: setDifference -> difference
This commit is contained in:
Aya Morisawa 2018-11-09 14:14:53 +09:00 committed by GitHub
parent 9aa65fb600
commit 3c0d2db3bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -18,8 +18,12 @@ export function erase<T>(x: T, xs: T[]): T[] {
return xs.filter(y => x !== y);
}
export function setDifference<T>(xs: T[], ys: T[]): T[] {
return xs.filter(x => !ys.includes(x));
/**
* Finds the array of all elements in the first array not contained in the second array.
* The order of result values are determined by the first array.
*/
export function difference<T>(includes: T[], excludes: T[]): T[] {
return includes.filter(x => !excludes.includes(x));
}
export function unique<T>(xs: T[]): T[] {

View File

@ -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, concat, setDifference } from '../../../prelude/array';
import { unique, concat, difference } from '../../../prelude/array';
const log = debug('misskey:activitypub');
@ -181,7 +181,7 @@ async function extractEmojis(tags: ITag[], host_: string) {
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 uris = difference(unique(concat([to || [], cc || []])), ignoreUris);
const users = await Promise.all(
uris.map(async uri => await resolvePerson(uri, null, resolver).catch(() => null))