From acc6f54557b2077a0cbc31857e3866c560fe94eb Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 19 Dec 2018 21:19:43 +0900 Subject: [PATCH] Update remote Emoji (#3680) --- src/models/emoji.ts | 2 ++ src/remote/activitypub/models/note.ts | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/models/emoji.ts b/src/models/emoji.ts index 8e75868e6..373d5f860 100644 --- a/src/models/emoji.ts +++ b/src/models/emoji.ts @@ -15,4 +15,6 @@ export type IEmoji = { url: string; aliases?: string[]; updatedAt?: Date; + /** AP object id */ + uri?: string; }; diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 10aa83342..bee2d943a 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -181,6 +181,20 @@ export async function extractEmojis(tags: ITag[], host_: string) { }); if (exists) { + if ((tag.updated != null && exists.updatedAt == null) + || (tag.id != null && exists.uri == null) + || (tag.updated != null && exists.updatedAt != null && new Date(tag.updated) > exists.updatedAt)) { + return await Emoji.findOneAndUpdate({ + host, + name, + }, { + $set: { + uri: tag.id, + url: tag.icon.url, + updatedAt: new Date(tag.updated), + } + }); + } return exists; } @@ -189,8 +203,10 @@ export async function extractEmojis(tags: ITag[], host_: string) { return await Emoji.insert({ host, name, + uri: tag.id, url: tag.icon.url, - aliases: [], + updatedAt: tag.updated ? new Date(tag.updated) : undefined, + aliases: [] }); }) );