diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-06-21 01:21:57 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-06-21 01:21:57 +0900 |
| commit | 79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89 (patch) | |
| tree | ed8f50f01cc50cf851dc0d0f399ed7e0f514f6c6 /src/remote/activitypub/models/note.ts | |
| parent | Disable transitions to avoid memory leak (diff) | |
| download | misskey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.tar.gz misskey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.tar.bz2 misskey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.zip | |
リモートユーザーのHTMLで表現されたプロフィールをMFMに変換するように
Diffstat (limited to 'src/remote/activitypub/models/note.ts')
| -rw-r--r-- | src/remote/activitypub/models/note.ts | 74 |
1 files changed, 2 insertions, 72 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index b0fe045e6d..85a8f89bc8 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -1,5 +1,4 @@ import * as mongo from 'mongodb'; -const parse5 = require('parse5'); import * as debug from 'debug'; import config from '../../../config'; @@ -10,79 +9,10 @@ import { INote as INoteActivityStreamsObject, IObject } from '../type'; import { resolvePerson, updatePerson } from './person'; import { resolveImage } from './image'; import { IRemoteUser, IUser } from '../../../models/user'; +import htmlToMFM from '../../../mfm/html-to-mfm'; const log = debug('misskey:activitypub'); -function parse(html: string): string { - const dom = parse5.parseFragment(html); - - let text = ''; - - dom.childNodes.forEach((n: any) => analyze(n)); - - return text.trim(); - - function getText(node: any) { - if (node.nodeName == '#text') return node.value; - - if (node.childNodes) { - return node.childNodes.map((n: any) => getText(n)).join(''); - } - - return ''; - } - - function analyze(node: any) { - switch (node.nodeName) { - case '#text': - text += node.value; - break; - - case 'br': - text += '\n'; - break; - - case 'a': - const txt = getText(node); - - // メンション - if (txt.startsWith('@')) { - const part = txt.split('@'); - - if (part.length == 2) { - //#region ホスト名部分が省略されているので復元する - const href = new URL(node.attrs.find((x: any) => x.name == 'href').value); - const acct = txt + '@' + href.hostname; - text += acct; - break; - //#endregion - } else if (part.length == 3) { - text += txt; - break; - } - } - - if (node.childNodes) { - node.childNodes.forEach((n: any) => analyze(n)); - } - break; - - case 'p': - text += '\n\n'; - if (node.childNodes) { - node.childNodes.forEach((n: any) => analyze(n)); - } - break; - - default: - if (node.childNodes) { - node.childNodes.forEach((n: any) => analyze(n)); - } - break; - } - } -} - /** * Noteをフェッチします。 * @@ -158,7 +88,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false const reply = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver) : null; // テキストのパース - const text = parse(note.content); + const text = htmlToMFM(note.content); // ユーザーの情報が古かったらついでに更新しておく if (actor.updatedAt == null || Date.now() - actor.updatedAt.getTime() > 1000 * 60 * 60 * 24) { |