logo

pleroma-fe

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

chat_message.js (2892B)


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