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 (2821B)


  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. currentUser: state => state.users.currentUser,
  68. restrictedNicknames: state => state.instance.restrictedNicknames
  69. }),
  70. popoverMarginStyle () {
  71. if (this.isCurrentUser) {
  72. return {}
  73. } else {
  74. return { left: 50 }
  75. }
  76. },
  77. ...mapGetters(['mergedConfig', 'findUser'])
  78. },
  79. data () {
  80. return {
  81. hovered: false,
  82. menuOpened: false
  83. }
  84. },
  85. methods: {
  86. onHover (bool) {
  87. this.$emit('hover', { isHovered: bool, messageChainId: this.chatViewItem.messageChainId })
  88. },
  89. async deleteMessage () {
  90. const confirmed = window.confirm(this.$t('chats.delete_confirm'))
  91. if (confirmed) {
  92. await this.$store.dispatch('deleteChatMessage', {
  93. messageId: this.chatViewItem.data.id,
  94. chatId: this.chatViewItem.data.chat_id
  95. })
  96. }
  97. this.hovered = false
  98. this.menuOpened = false
  99. }
  100. }
  101. }
  102. export default ChatMessage