logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

emoji_reactions.js (2773B)


  1. import UserAvatar from '../user_avatar/user_avatar.vue'
  2. import UserListPopover from '../user_list_popover/user_list_popover.vue'
  3. import StillImage from 'src/components/still-image/still-image.vue'
  4. import { library } from '@fortawesome/fontawesome-svg-core'
  5. import {
  6. faPlus,
  7. faMinus,
  8. faCheck
  9. } from '@fortawesome/free-solid-svg-icons'
  10. library.add(
  11. faPlus,
  12. faMinus,
  13. faCheck
  14. )
  15. const EMOJI_REACTION_COUNT_CUTOFF = 12
  16. const EmojiReactions = {
  17. name: 'EmojiReactions',
  18. components: {
  19. UserAvatar,
  20. UserListPopover,
  21. StillImage
  22. },
  23. props: ['status'],
  24. data: () => ({
  25. showAll: false
  26. }),
  27. computed: {
  28. tooManyReactions () {
  29. return this.status.emoji_reactions.length > EMOJI_REACTION_COUNT_CUTOFF
  30. },
  31. emojiReactions () {
  32. return this.showAll
  33. ? this.status.emoji_reactions
  34. : this.status.emoji_reactions.slice(0, EMOJI_REACTION_COUNT_CUTOFF)
  35. },
  36. showMoreString () {
  37. return `+${this.status.emoji_reactions.length - EMOJI_REACTION_COUNT_CUTOFF}`
  38. },
  39. accountsForEmoji () {
  40. return this.status.emoji_reactions.reduce((acc, reaction) => {
  41. acc[reaction.name] = reaction.accounts || []
  42. return acc
  43. }, {})
  44. },
  45. loggedIn () {
  46. return !!this.$store.state.users.currentUser
  47. },
  48. remoteInteractionLink () {
  49. return this.$store.getters.remoteInteractionLink({ statusId: this.status.id })
  50. }
  51. },
  52. methods: {
  53. toggleShowAll () {
  54. this.showAll = !this.showAll
  55. },
  56. reactedWith (emoji) {
  57. return this.status.emoji_reactions.find(r => r.name === emoji).me
  58. },
  59. async fetchEmojiReactionsByIfMissing () {
  60. const hasNoAccounts = this.status.emoji_reactions.find(r => !r.accounts)
  61. if (hasNoAccounts) {
  62. return await this.$store.dispatch('fetchEmojiReactionsBy', this.status.id)
  63. }
  64. },
  65. reactWith (emoji) {
  66. this.$store.dispatch('reactWithEmoji', { id: this.status.id, emoji })
  67. },
  68. unreact (emoji) {
  69. this.$store.dispatch('unreactWithEmoji', { id: this.status.id, emoji })
  70. },
  71. async emojiOnClick (emoji, event) {
  72. if (!this.loggedIn) return
  73. await this.fetchEmojiReactionsByIfMissing()
  74. if (this.reactedWith(emoji)) {
  75. this.unreact(emoji)
  76. } else {
  77. this.reactWith(emoji)
  78. }
  79. },
  80. counterTriggerAttrs (reaction) {
  81. return {
  82. class: [
  83. 'btn',
  84. 'button-default',
  85. 'emoji-reaction-count-button',
  86. {
  87. '-picked-reaction': this.reactedWith(reaction.name),
  88. toggled: this.reactedWith(reaction.name)
  89. }
  90. ],
  91. 'aria-label': this.$t('status.reaction_count_label', { num: reaction.count }, reaction.count)
  92. }
  93. }
  94. }
  95. }
  96. export default EmojiReactions