diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 03a50fece..bf5ebfdbf 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -129,6 +129,31 @@ export class NoteRepository extends Repository { }; } + async function populateEmojis(emojiNames: string[], noteUserHost: string | null, reactionNames: string[]) { + const where = [] as {}[]; + + if (emojiNames?.length > 0) { + where.push({ + name: In(emojiNames), + host: noteUserHost + }); + } + + if (reactionNames?.length > 0) { + where.push({ + name: In(reactionNames.map(x => x.replace(/:/g, ''))), + host: null + }); + } + + if (where.length === 0) return []; + + return Emojis.find({ + where, + select: ['name', 'host', 'url', 'aliases'] + }); + } + async function populateMyReaction() { const reaction = await NoteReactions.findOne({ userId: meId!, @@ -148,8 +173,6 @@ export class NoteRepository extends Repository { text = `【${note.name}】\n${(note.text || '').trim()}\n${note.uri}`; } - const reactionEmojis = unique(concat([note.emojis, Object.keys(note.reactions)])); - const packed = await awaitAll({ id: note.id, createdAt: note.createdAt.toISOString(), @@ -166,10 +189,7 @@ export class NoteRepository extends Repository { repliesCount: note.repliesCount, reactions: note.reactions, tags: note.tags.length > 0 ? note.tags : undefined, - emojis: reactionEmojis.length > 0 ? Emojis.find({ - name: In(reactionEmojis), - host: host - }) : [], + emojis: populateEmojis(note.emojis, host, Object.keys(note.reactions)), fileIds: note.fileIds, files: DriveFiles.packMany(note.fileIds), replyId: note.replyId,