logo

pleroma-fe

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

chat_message.js (3038B)


  1. import { mapState, mapGetters } from 'vuex'
  2. import { mapState as mapPiniaState } from 'pinia'
  3. import Popover from '../popover/popover.vue'
  4. import Attachment from '../attachment/attachment.vue'
  5. import UserAvatar from '../user_avatar/user_avatar.vue'
  6. import Gallery from '../gallery/gallery.vue'
  7. import LinkPreview from '../link-preview/link-preview.vue'
  8. import StatusContent from '../status_content/status_content.vue'
  9. import ChatMessageDate from '../chat_message_date/chat_message_date.vue'
  10. import { defineAsyncComponent } from 'vue'
  11. import { library } from '@fortawesome/fontawesome-svg-core'
  12. import {
  13. faTimes,
  14. faEllipsisH
  15. } from '@fortawesome/free-solid-svg-icons'
  16. import { useInterfaceStore } from 'src/stores/interface'
  17. library.add(
  18. faTimes,
  19. faEllipsisH
  20. )
  21. const ChatMessage = {
  22. name: 'ChatMessage',
  23. props: [
  24. 'author',
  25. 'edited',
  26. 'noHeading',
  27. 'chatViewItem',
  28. 'hoveredMessageChain'
  29. ],
  30. emits: ['hover'],
  31. components: {
  32. Popover,
  33. Attachment,
  34. StatusContent,
  35. UserAvatar,
  36. Gallery,
  37. LinkPreview,
  38. ChatMessageDate,
  39. UserPopover: defineAsyncComponent(() => import('../user_popover/user_popover.vue'))
  40. },
  41. computed: {
  42. // Returns HH:MM (hours and minutes) in local time.
  43. createdAt () {
  44. const time = this.chatViewItem.data.created_at
  45. return time.toLocaleTimeString('en', { hour: '2-digit', minute: '2-digit', hour12: false })
  46. },
  47. isCurrentUser () {
  48. return this.message.account_id === this.currentUser.id
  49. },
  50. message () {
  51. return this.chatViewItem.data
  52. },
  53. isMessage () {
  54. return this.chatViewItem.type === 'message'
  55. },
  56. messageForStatusContent () {
  57. return {
  58. summary: '',
  59. emojis: this.message.emojis,
  60. raw_html: this.message.content || '',
  61. text: this.message.content || '',
  62. attachments: this.message.attachments
  63. }
  64. },
  65. hasAttachment () {
  66. return this.message.attachments.length > 0
  67. },
  68. ...mapPiniaState(useInterfaceStore, {
  69. betterShadow: store => store.browserSupport.cssFilter
  70. }),
  71. ...mapState({
  72. currentUser: state => state.users.currentUser,
  73. restrictedNicknames: state => state.instance.restrictedNicknames
  74. }),
  75. popoverMarginStyle () {
  76. if (this.isCurrentUser) {
  77. return {}
  78. } else {
  79. return { left: 50 }
  80. }
  81. },
  82. ...mapGetters(['mergedConfig', 'findUser'])
  83. },
  84. data () {
  85. return {
  86. hovered: false,
  87. menuOpened: false
  88. }
  89. },
  90. methods: {
  91. onHover (bool) {
  92. this.$emit('hover', { isHovered: bool, messageChainId: this.chatViewItem.messageChainId })
  93. },
  94. async deleteMessage () {
  95. const confirmed = window.confirm(this.$t('chats.delete_confirm'))
  96. if (confirmed) {
  97. await this.$store.dispatch('deleteChatMessage', {
  98. messageId: this.chatViewItem.data.id,
  99. chatId: this.chatViewItem.data.chat_id
  100. })
  101. }
  102. this.hovered = false
  103. this.menuOpened = false
  104. }
  105. }
  106. }
  107. export default ChatMessage