From 99fc77b6787bf16e772d46493067de75ea219bb7 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 3 Apr 2020 22:51:38 +0900 Subject: APメンションはaudienceじゃなくてtagを参照するなど (#6128) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * APメンションはaudienceじゃなくてtagを参照するなど * AP/tag/Mentionではurlじゃなくてuriを提示する * createPersonでaliasが入力された場合に対応 * AP HTMLパースでMention/Hashtag判定にtagを使うように * fix * indent * use hashtag name * fix * URLエンコード不要だったら<>を使わないの条件が消えたたのを修正 --- src/remote/activitypub/models/note.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/remote/activitypub/models/note.ts') diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 55b5440e6b..1e633704d4 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -6,9 +6,9 @@ import post from '../../../services/note/create'; import { resolvePerson, updatePerson } from './person'; import { resolveImage } from './image'; import { IRemoteUser } from '../../../models/entities/user'; -import { fromHtml } from '../../../mfm/fromHtml'; -import { ITag, extractHashtags } from './tag'; -import { unique } from '../../../prelude/array'; +import { htmlToMfm } from '../misc/html-to-mfm'; +import { extractApHashtags } from './tag'; +import { unique, toArray, toSingle } from '../../../prelude/array'; import { extractPollFromQuestion } from './question'; import vote from '../../../services/note/polls/vote'; import { apLogger } from '../logger'; @@ -17,7 +17,7 @@ import { deliverQuestionUpdate } from '../../../services/note/polls/update'; import { extractDbHost, toPuny } from '../../../misc/convert-host'; import { Notes, Emojis, Polls, MessagingMessages } from '../../../models'; import { Note } from '../../../models/entities/note'; -import { IObject, getOneApId, getApId, validPost, IPost } from '../type'; +import { IObject, getOneApId, getApId, validPost, IPost, isEmoji } from '../type'; import { Emoji } from '../../../models/entities/emoji'; import { genId } from '../../../misc/gen-id'; import { fetchMeta } from '../../../misc/fetch-meta'; @@ -25,6 +25,7 @@ import { ensure } from '../../../prelude/ensure'; import { getApLock } from '../../../misc/app-lock'; import { createMessage } from '../../../services/messages/create'; import { parseAudience } from '../audience'; +import { extractApMentions } from './mention'; const logger = apLogger; @@ -113,7 +114,6 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s const noteAudience = await parseAudience(actor, note.to, note.cc); let visibility = noteAudience.visibility; const visibleUsers = noteAudience.visibleUsers; - const apMentions = noteAudience.mentionedUsers; // Audience (to, cc) が指定されてなかった場合 if (visibility === 'specified' && visibleUsers.length === 0) { @@ -125,7 +125,8 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s let isTalk = note._misskey_talk && visibility === 'specified'; - const apHashtags = await extractHashtags(note.tag); + const apMentions = await extractApMentions(note.tag); + const apHashtags = await extractApHashtags(note.tag); // 添付ファイル // TODO: attachmentは必ずしもImageではない @@ -210,7 +211,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s const cw = note.summary === '' ? null : note.summary; // テキストのパース - const text = note._misskey_content || (note.content ? fromHtml(note.content) : null); + const text = note._misskey_content || (note.content ? htmlToMfm(note.content, note.tag) : null); // vote if (reply && reply.hasPoll) { @@ -319,15 +320,16 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver): } } -export async function extractEmojis(tags: ITag[], host: string): Promise { +export async function extractEmojis(tags: IObject | IObject[], host: string): Promise { host = toPuny(host); if (!tags) return []; - const eomjiTags = tags.filter(tag => tag.type === 'Emoji' && tag.icon && tag.icon.url && tag.name); + const eomjiTags = toArray(tags).filter(isEmoji); return await Promise.all(eomjiTags.map(async tag => { const name = tag.name!.replace(/^:/, '').replace(/:$/, ''); + tag.icon = toSingle(tag.icon); const exists = await Emojis.findOne({ host, -- cgit v1.2.3-freya