pleroma-fe/src/components/chat_message/chat_message.js

117 lines
3.1 KiB
JavaScript
Raw Normal View History

2023-04-05 21:06:37 -06:00
import { mapState as mapPiniaState } from 'pinia'
2026-01-06 16:23:17 +02:00
import { defineAsyncComponent } from 'vue'
import { mapGetters, mapState } from 'vuex'
2026-01-08 17:26:52 +02:00
2020-05-07 16:10:53 +03:00
import Attachment from '../attachment/attachment.vue'
2026-01-06 16:23:17 +02:00
import ChatMessageDate from '../chat_message_date/chat_message_date.vue'
2020-05-07 16:10:53 +03:00
import Gallery from '../gallery/gallery.vue'
import LinkPreview from '../link-preview/link-preview.vue'
2026-01-06 16:23:17 +02:00
import Popover from '../popover/popover.vue'
2020-05-07 16:10:53 +03:00
import StatusContent from '../status_content/status_content.vue'
2026-01-06 16:23:17 +02:00
import UserAvatar from '../user_avatar/user_avatar.vue'
2020-10-20 21:18:23 +03:00
2026-01-29 20:40:00 +02:00
import { useInstanceStore } from 'src/stores/instance.js'
import { useInterfaceStore } from 'src/stores/interface'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faEllipsisH, faTimes } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faTimes, faEllipsisH)
2020-05-07 16:10:53 +03:00
const ChatMessage = {
name: 'ChatMessage',
props: [
'author',
'edited',
'noHeading',
'chatViewItem',
2026-01-06 16:22:52 +02:00
'hoveredMessageChain',
2020-05-07 16:10:53 +03:00
],
emits: ['hover'],
2020-05-07 16:10:53 +03:00
components: {
Popover,
Attachment,
StatusContent,
UserAvatar,
Gallery,
LinkPreview,
2022-07-20 12:54:51 +03:00
ChatMessageDate,
2026-01-06 16:22:52 +02:00
UserPopover: defineAsyncComponent(
() => import('../user_popover/user_popover.vue'),
),
2020-05-07 16:10:53 +03:00
},
computed: {
// Returns HH:MM (hours and minutes) in local time.
2026-01-06 16:22:52 +02:00
createdAt() {
2020-05-07 16:10:53 +03:00
const time = this.chatViewItem.data.created_at
2026-01-06 16:22:52 +02:00
return time.toLocaleTimeString('en', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
})
2020-05-07 16:10:53 +03:00
},
2026-01-06 16:22:52 +02:00
isCurrentUser() {
2020-05-07 16:10:53 +03:00
return this.message.account_id === this.currentUser.id
},
2026-01-06 16:22:52 +02:00
message() {
2020-05-07 16:10:53 +03:00
return this.chatViewItem.data
},
2026-01-06 16:22:52 +02:00
isMessage() {
2020-05-07 16:10:53 +03:00
return this.chatViewItem.type === 'message'
},
2026-01-06 16:22:52 +02:00
messageForStatusContent() {
2020-05-07 16:10:53 +03:00
return {
summary: '',
emojis: this.message.emojis,
2021-06-13 21:42:25 +03:00
raw_html: this.message.content || '',
text: this.message.content || '',
2026-01-06 16:22:52 +02:00
attachments: this.message.attachments,
2020-05-07 16:10:53 +03:00
}
},
2026-01-06 16:22:52 +02:00
hasAttachment() {
2020-05-07 16:10:53 +03:00
return this.message.attachments.length > 0
},
2023-04-05 21:06:37 -06:00
...mapPiniaState(useInterfaceStore, {
2026-01-06 16:22:52 +02:00
betterShadow: (store) => store.browserSupport.cssFilter,
2023-04-05 21:06:37 -06:00
}),
2020-05-07 16:10:53 +03:00
...mapState({
2026-01-06 16:22:52 +02:00
currentUser: (state) => state.users.currentUser,
restrictedNicknames: (state) => useInstanceStore().restrictedNicknames,
2020-05-07 16:10:53 +03:00
}),
2026-01-06 16:22:52 +02:00
popoverMarginStyle() {
2020-05-07 16:10:53 +03:00
if (this.isCurrentUser) {
return {}
} else {
return { left: 50 }
}
},
2026-01-06 16:22:52 +02:00
...mapGetters(['mergedConfig', 'findUser']),
2020-05-07 16:10:53 +03:00
},
2026-01-06 16:22:52 +02:00
data() {
2020-05-07 16:10:53 +03:00
return {
hovered: false,
2026-01-06 16:22:52 +02:00
menuOpened: false,
2020-05-07 16:10:53 +03:00
}
},
methods: {
2026-01-06 16:22:52 +02:00
onHover(bool) {
this.$emit('hover', {
isHovered: bool,
messageChainId: this.chatViewItem.messageChainId,
})
2020-05-07 16:10:53 +03:00
},
2026-01-06 16:22:52 +02:00
async deleteMessage() {
2020-05-07 16:10:53 +03:00
const confirmed = window.confirm(this.$t('chats.delete_confirm'))
if (confirmed) {
await this.$store.dispatch('deleteChatMessage', {
messageId: this.chatViewItem.data.id,
2026-01-06 16:22:52 +02:00
chatId: this.chatViewItem.data.chat_id,
2020-05-07 16:10:53 +03:00
})
}
this.hovered = false
this.menuOpened = false
2026-01-06 16:22:52 +02:00
},
},
2020-05-07 16:10:53 +03:00
}
export default ChatMessage