diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-12-02 18:05:33 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-12-02 18:05:33 +0900 |
| commit | 3a2dc95850cf09c6d02841938e6d4befa22d9f3b (patch) | |
| tree | 29bbcce2fa89670f4590f3e579566afa0089bcea /src/remote | |
| parent | 10.60.0 (diff) | |
| download | sharkey-3a2dc95850cf09c6d02841938e6d4befa22d9f3b.tar.gz sharkey-3a2dc95850cf09c6d02841938e6d4befa22d9f3b.tar.bz2 sharkey-3a2dc95850cf09c6d02841938e6d4befa22d9f3b.zip | |
No MFM parsing when remote note (#3470)
* Use tag for hashtag detection of remote note
* No MFM parsing when remote note
Diffstat (limited to 'src/remote')
| -rw-r--r-- | src/remote/activitypub/models/note.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 9fc03c777d..a45946a050 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -10,7 +10,7 @@ import { resolvePerson, updatePerson } from './person'; import { resolveImage } from './image'; import { IRemoteUser, IUser } from '../../../models/user'; import htmlToMFM from '../../../mfm/html-to-mfm'; -import Emoji from '../../../models/emoji'; +import Emoji, { IEmoji } from '../../../models/emoji'; import { ITag } from './tag'; import { toUnicode } from 'punycode'; import { unique, concat, difference } from '../../../prelude/array'; @@ -84,6 +84,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false const apMentions = await extractMentionedUsers(actor, note.to, note.cc, resolver); + const apHashtags = await extractHashtags(note.tag); + // 添付ファイル // TODO: attachmentは必ずしもImageではない // TODO: attachmentは必ずしも配列ではない @@ -108,10 +110,13 @@ export async function createNote(value: any, resolver?: Resolver, silent = false // テキストのパース const text = note._misskey_content ? note._misskey_content : htmlToMFM(note.content); - await extractEmojis(note.tag, actor.host).catch(e => { + const emojis = await extractEmojis(note.tag, actor.host).catch(e => { console.log(`extractEmojis: ${e}`); + return [] as IEmoji[]; }); + const apEmojis = emojis.map(emoji => emoji.name); + // ユーザーの情報が古かったらついでに更新しておく if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { updatePerson(note.attributedTo); @@ -130,6 +135,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false visibility, visibleUsers, apMentions, + apHashtags, + apEmojis, uri: note.id }, silent); } @@ -199,3 +206,14 @@ async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: strin return users.filter(x => x != null); } + +function extractHashtags(tags: ITag[]) { + if (!tags) return []; + + const hashtags = tags.filter(tag => tag.type === 'Hashtag' && typeof tag.name == 'string'); + + return hashtags.map(tag => { + const m = tag.name.match(/^#(.+)/); + return m ? m[1] : null; + }).filter(x => x != null); +} |