No MFM parsing when remote note (#3470)

* Use tag for hashtag detection of remote note

* No MFM parsing when remote note
This commit is contained in:
MeiMei
2018-12-02 18:05:33 +09:00
committed by syuilo
parent 163cf49f16
commit 3a2dc95850
2 changed files with 35 additions and 9 deletions

View File

@ -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);
}