APメンションはaudienceじゃなくてtagを参照するなど (#6128)
* APメンションはaudienceじゃなくてtagを参照するなど * AP/tag/Mentionではurlじゃなくてuriを提示する * createPersonでaliasが入力された場合に対応 * AP HTMLパースでMention/Hashtag判定にtagを使うように * fix * indent * use hashtag name * fix * URLエンコード不要だったら<>を使わないの条件が消えたたのを修正
This commit is contained in:
parent
8bb311df51
commit
99fc77b678
8 changed files with 128 additions and 64 deletions
24
src/remote/activitypub/models/mention.ts
Normal file
24
src/remote/activitypub/models/mention.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { toArray, unique } from '../../../prelude/array';
|
||||
import { IObject, isMention, IApMention } from '../type';
|
||||
import { resolvePerson } from './person';
|
||||
import * as promiseLimit from 'promise-limit';
|
||||
import Resolver from '../resolver';
|
||||
import { User } from '../../../models/entities/user';
|
||||
|
||||
export async function extractApMentions(tags: IObject | IObject[] | null | undefined) {
|
||||
const hrefs = unique(extractApMentionObjects(tags).map(x => x.href as string));
|
||||
|
||||
const resolver = new Resolver();
|
||||
|
||||
const limit = promiseLimit<User | null>(2);
|
||||
const mentionedUsers = (await Promise.all(
|
||||
hrefs.map(x => limit(() => resolvePerson(x, resolver).catch(() => null)))
|
||||
)).filter((x): x is User => x != null);
|
||||
|
||||
return mentionedUsers;
|
||||
}
|
||||
|
||||
export function extractApMentionObjects(tags: IObject | IObject[] | null | undefined): IApMention[] {
|
||||
if (tags == null) return [];
|
||||
return toArray(tags).filter(isMention);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue