diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-11-02 08:59:40 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-11-02 08:59:40 +0900 |
| commit | 80b5fda292efd70cc749910e3672d50c9a70a72e (patch) | |
| tree | a8f287c9c60a532112801d084fcb7d5b8c4e3650 /src/remote/activitypub/models/note.ts | |
| parent | Fix bug (diff) | |
| download | misskey-80b5fda292efd70cc749910e3672d50c9a70a72e.tar.gz misskey-80b5fda292efd70cc749910e3672d50c9a70a72e.tar.bz2 misskey-80b5fda292efd70cc749910e3672d50c9a70a72e.zip | |
Remote custom emojis (#3074)
* Remote custom emojis
* んほおおおおお
Diffstat (limited to 'src/remote/activitypub/models/note.ts')
| -rw-r--r-- | src/remote/activitypub/models/note.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index d49cf53079..be6c1bcd18 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -10,6 +10,9 @@ 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 { ITag } from './tag'; +import { toUnicode } from 'punycode'; const log = debug('misskey:activitypub'); @@ -93,6 +96,10 @@ 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 => { + console.log(`extractEmojis: ${e}`); + }); + // ユーザーの情報が古かったらついでに更新しておく if (actor.updatedAt == null || Date.now() - actor.updatedAt.getTime() > 1000 * 60 * 60 * 24) { updatePerson(note.attributedTo); @@ -135,3 +142,35 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver): // 添付されてきたNote Objectは偽装されている可能性があるため、常にuriを指定してサーバーフェッチを行う。 return await createNote(uri, resolver); } + +async function extractEmojis(tags: ITag[], host_: string) { + const host = toUnicode(host_.toLowerCase()); + + if (!tags) return []; + + const eomjiTags = tags.filter(tag => tag.type === 'Emoji' && tag.icon && tag.icon.url); + + return await Promise.all( + eomjiTags.map(async tag => { + const name = tag.name.replace(/^:/, '').replace(/:$/, ''); + + const exists = await Emoji.findOne({ + host, + name + }); + + if (exists) { + return exists; + } + + log(`register emoji host=${host}, name=${name}`); + + return await Emoji.insert({ + host, + name, + url: tag.icon.url, + aliases: [], + }); + }) + ); +} |