emoji_reactions

This commit is contained in:
cutls 2023-02-23 15:02:51 +09:00 committed by cutestnekoaqua
parent 2a1de51140
commit 0c9b10f307
No known key found for this signature in database
GPG key ID: 6BF0964A5069C1E0
3 changed files with 27 additions and 9 deletions

View file

@ -6,5 +6,7 @@ namespace Entity {
me: boolean
name: string
accounts?: Array<Account>
url: string
static_url: string
}
}

View file

@ -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<MegalodonEntity.Reaction> => {
export const mapReactions = (host: string, r: { [key: string]: number }, myReaction: string, emojiData: MisskeyEntity.Emoji[] | MisskeyEntity.EmojiKeyValue): Array<MegalodonEntity.Reaction> => {
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<Entity.Reaction>): Array<MegalodonEntity.Reaction> => {
export const reactions = (r: Array<Entity.Reaction>, host: string, emojiData: MisskeyEntity.Emoji[] | MisskeyEntity.EmojiKeyValue): Array<MegalodonEntity.Reaction> => {
const result: Array<MegalodonEntity.Reaction> = []
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`
})
}
}

View file

@ -15,7 +15,7 @@ namespace MisskeyEntity {
renoteCount: number
repliesCount: number
reactions: { [key: string]: number }
emojis: Array<Emoji>
emojis: Array<Emoji> | EmojiKeyValue
fileIds: Array<string>
files: Array<File>
replyId: string | null
@ -27,6 +27,7 @@ namespace MisskeyEntity {
tags?: Array<string>
poll?: Poll
mentions?: Array<string>
myReaction?: string
myReaction?: string,
reactionEmojis?: EmojiKeyValue
}
}