2020-02-11 12:24:51 +00:00
|
|
|
import UserAvatar from '../user_avatar/user_avatar.vue'
|
2020-07-16 14:42:16 +00:00
|
|
|
import UserListPopover from '../user_list_popover/user_list_popover.vue'
|
2020-02-11 12:24:51 +00:00
|
|
|
|
|
|
|
const EMOJI_REACTION_COUNT_CUTOFF = 12
|
2020-01-14 08:06:14 +00:00
|
|
|
|
|
|
|
const EmojiReactions = {
|
|
|
|
name: 'EmojiReactions',
|
2020-02-11 12:24:51 +00:00
|
|
|
components: {
|
2020-02-28 16:39:47 +00:00
|
|
|
UserAvatar,
|
2020-07-16 14:42:16 +00:00
|
|
|
UserListPopover
|
2020-02-11 12:24:51 +00:00
|
|
|
},
|
2020-01-14 08:06:14 +00:00
|
|
|
props: ['status'],
|
2020-02-11 12:24:51 +00:00
|
|
|
data: () => ({
|
2020-02-28 16:39:47 +00:00
|
|
|
showAll: false
|
2020-02-11 12:24:51 +00:00
|
|
|
}),
|
2020-01-14 08:06:14 +00:00
|
|
|
computed: {
|
2020-02-11 12:24:51 +00:00
|
|
|
tooManyReactions () {
|
|
|
|
return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF
|
|
|
|
},
|
2020-01-14 08:06:14 +00:00
|
|
|
emojiReactions () {
|
2020-02-11 12:24:51 +00:00
|
|
|
return this.showAll
|
|
|
|
? this.status.emoji_reactions
|
|
|
|
: this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF)
|
|
|
|
},
|
|
|
|
showMoreString () {
|
|
|
|
return `+${this.status.emoji_reactions.length - EMOJI_REACTION_COUNT_CUTOFF}`
|
|
|
|
},
|
|
|
|
accountsForEmoji () {
|
|
|
|
return this.status.emoji_reactions.reduce((acc, reaction) => {
|
2022-08-11 17:14:05 +00:00
|
|
|
if (reaction.url) {
|
|
|
|
acc[reaction.url] = reaction.accounts || []
|
|
|
|
} else {
|
|
|
|
acc[reaction.name] = reaction.accounts || []
|
|
|
|
}
|
2020-02-11 12:24:51 +00:00
|
|
|
return acc
|
|
|
|
}, {})
|
|
|
|
},
|
|
|
|
loggedIn () {
|
|
|
|
return !!this.$store.state.users.currentUser
|
2020-01-14 08:06:14 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-02-11 12:24:51 +00:00
|
|
|
toggleShowAll () {
|
|
|
|
this.showAll = !this.showAll
|
|
|
|
},
|
2020-01-14 08:06:14 +00:00
|
|
|
reactedWith (emoji) {
|
2020-02-11 12:24:51 +00:00
|
|
|
return this.status.emoji_reactions.find(r => r.name === emoji).me
|
|
|
|
},
|
|
|
|
fetchEmojiReactionsByIfMissing () {
|
|
|
|
const hasNoAccounts = this.status.emoji_reactions.find(r => !r.accounts)
|
|
|
|
if (hasNoAccounts) {
|
|
|
|
this.$store.dispatch('fetchEmojiReactionsBy', this.status.id)
|
|
|
|
}
|
2020-01-14 08:06:14 +00:00
|
|
|
},
|
|
|
|
reactWith (emoji) {
|
|
|
|
this.$store.dispatch('reactWithEmoji', { id: this.status.id, emoji })
|
|
|
|
},
|
|
|
|
unreact (emoji) {
|
|
|
|
this.$store.dispatch('unreactWithEmoji', { id: this.status.id, emoji })
|
|
|
|
},
|
|
|
|
emojiOnClick (emoji, event) {
|
2020-02-11 12:24:51 +00:00
|
|
|
if (!this.loggedIn) return
|
|
|
|
|
2020-01-14 08:06:14 +00:00
|
|
|
if (this.reactedWith(emoji)) {
|
|
|
|
this.unreact(emoji)
|
|
|
|
} else {
|
|
|
|
this.reactWith(emoji)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EmojiReactions
|