diff --git a/megalodon/src/entities/reaction.ts b/megalodon/src/entities/reaction.ts index 8c626f9..f92e1de 100644 --- a/megalodon/src/entities/reaction.ts +++ b/megalodon/src/entities/reaction.ts @@ -6,5 +6,7 @@ namespace Entity { me: boolean name: string accounts?: Array + url: string + static_url: string } } diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts index 8f1a407..b6e5bc9 100644 --- a/megalodon/src/misskey/api_client.ts +++ b/megalodon/src/misskey/api_client.ts @@ -258,31 +258,44 @@ namespace MisskeyAPI { application: null, language: null, pinned: null, - emoji_reactions: mapReactions(n.reactions, n.myReaction), + emoji_reactions: mapReactions(host, n.reactions, n.myReaction || '', n.reactionEmojis || {}), bookmarked: false, quote: n.renote && n.text ? note(n.renote, host) : null } } - - export const mapReactions = (r: { [key: string]: number }, myReaction?: string): Array => { + export const mapReactions = (host: string, r: { [key: string]: number }, myReaction: string, emojiData: MisskeyEntity.Emoji[] | MisskeyEntity.EmojiKeyValue): Array => { + if (isEmojiArr(emojiData)) { + return emojiData.map((e) => {return { + count: 0, me: false, name: e.name, url: e.url, static_url: e.url + }}) + } return Object.keys(r).map(key => { if (myReaction && key === myReaction) { return { count: r[key], me: true, - name: key + name: key, + url: emojiData[key] || `https://${host}/${key.replace(/[:@.]/g, '')}.webp`, + static_url: emojiData[key] || `https://${host}/${key.replace(/[:@.]/g, '')}.webp` } } return { count: r[key], me: false, - name: key + name: key, + url: emojiData[key] || `https://${host}/${key.replace(/[:@.]/g, '')}.webp`, + static_url: emojiData[key] || `https://${host}/${key.replace(/[:@.]/g, '')}.webp` } }) } - export const reactions = (r: Array): Array => { + export const reactions = (r: Array, host: string, emojiData: MisskeyEntity.Emoji[] | MisskeyEntity.EmojiKeyValue): Array => { const result: Array = [] + if (isEmojiArr(emojiData)) { + return emojiData.map((e) => {return { + count: 0, me: false, name: e.name, url: e.url, static_url: e.url + }}) + } for (const e of r) { const i = result.findIndex(res => res.name === e.type) if (i >= 0) { @@ -291,7 +304,9 @@ namespace MisskeyAPI { result.push({ count: 1, me: false, - name: e.type + name: e.type, + url: emojiData[e.type] || `https://${host}/${e.type.replace(/[:@.]/g, '')}.webp`, + static_url: emojiData[e.type] || `https://${host}/${e.type.replace(/[:@.]/g, '')}.webp` }) } } diff --git a/megalodon/src/misskey/entities/note.ts b/megalodon/src/misskey/entities/note.ts index 1d7207d..9a714cf 100644 --- a/megalodon/src/misskey/entities/note.ts +++ b/megalodon/src/misskey/entities/note.ts @@ -15,7 +15,7 @@ namespace MisskeyEntity { renoteCount: number repliesCount: number reactions: { [key: string]: number } - emojis: Array + emojis: Array | EmojiKeyValue fileIds: Array files: Array replyId: string | null @@ -27,6 +27,7 @@ namespace MisskeyEntity { tags?: Array poll?: Poll mentions?: Array - myReaction?: string + myReaction?: string, + reactionEmojis?: EmojiKeyValue } }