mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 12:37:56 +00:00
These fixes are all auto generated and can be merged directly Fixes the following issues 1. Event used on components should be hypenated 2. Attribute orders in components 3. Use `unmounted` instead of `destroyed` 4. Add explicit `emits` declarations for components, autofixed [using this script](https://gist.github.com/scmmishra/6f549109b96400006bb69bbde392eddf) We ignore the top level v-if for now, we will fix it later
128 lines
2.9 KiB
Vue
128 lines
2.9 KiB
Vue
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import { hasPressedCommand } from 'shared/helpers/KeyboardHelpers';
|
|
import GalleryView from '../components/GalleryView.vue';
|
|
import { timeStampAppendedURL } from 'dashboard/helper/URLHelper';
|
|
|
|
const ALLOWED_FILE_TYPES = {
|
|
IMAGE: 'image',
|
|
VIDEO: 'video',
|
|
AUDIO: 'audio',
|
|
IG_REEL: 'ig_reel',
|
|
};
|
|
|
|
export default {
|
|
components: {
|
|
GalleryView,
|
|
},
|
|
props: {
|
|
attachment: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
},
|
|
emits: ['error'],
|
|
data() {
|
|
return {
|
|
show: false,
|
|
isImageError: false,
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
currentChatAttachments: 'getSelectedChatAttachments',
|
|
}),
|
|
isImage() {
|
|
return this.attachment.file_type === ALLOWED_FILE_TYPES.IMAGE;
|
|
},
|
|
isVideo() {
|
|
return (
|
|
this.attachment.file_type === ALLOWED_FILE_TYPES.VIDEO ||
|
|
this.attachment.file_type === ALLOWED_FILE_TYPES.IG_REEL
|
|
);
|
|
},
|
|
isAudio() {
|
|
return this.attachment.file_type === ALLOWED_FILE_TYPES.AUDIO;
|
|
},
|
|
timeStampURL() {
|
|
return timeStampAppendedURL(this.dataUrl);
|
|
},
|
|
attachmentTypeClasses() {
|
|
return {
|
|
image: this.isImage,
|
|
video: this.isVideo,
|
|
};
|
|
},
|
|
filteredCurrentChatAttachments() {
|
|
const attachments = this.currentChatAttachments.filter(attachment =>
|
|
['image', 'video', 'audio'].includes(attachment.file_type)
|
|
);
|
|
return attachments;
|
|
},
|
|
dataUrl() {
|
|
return this.attachment.data_url;
|
|
},
|
|
imageWidth() {
|
|
return this.attachment.width ? `${this.attachment.width}px` : 'auto';
|
|
},
|
|
imageHeight() {
|
|
return this.attachment.height ? `${this.attachment.height}px` : 'auto';
|
|
},
|
|
},
|
|
watch: {
|
|
attachment() {
|
|
this.isImageError = false;
|
|
},
|
|
},
|
|
methods: {
|
|
onClose() {
|
|
this.show = false;
|
|
},
|
|
onClick(e) {
|
|
if (hasPressedCommand(e)) {
|
|
window.open(this.attachment.data_url, '_blank');
|
|
return;
|
|
}
|
|
this.show = true;
|
|
},
|
|
onImgError() {
|
|
this.isImageError = true;
|
|
this.$emit('error');
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="message-text__wrap" :class="attachmentTypeClasses">
|
|
<img
|
|
v-if="isImage && !isImageError"
|
|
class="bg-woot-200 dark:bg-woot-900"
|
|
:src="dataUrl"
|
|
:width="imageWidth"
|
|
:height="imageHeight"
|
|
@click="onClick"
|
|
@error="onImgError"
|
|
/>
|
|
<video
|
|
v-if="isVideo"
|
|
:src="dataUrl"
|
|
muted
|
|
playsInline
|
|
@error="onImgError"
|
|
@click="onClick"
|
|
/>
|
|
<audio v-else-if="isAudio" controls class="skip-context-menu mb-0.5">
|
|
<source :src="timeStampURL" />
|
|
</audio>
|
|
<GalleryView
|
|
v-if="show"
|
|
v-model:show="show"
|
|
:attachment="attachment"
|
|
:all-attachments="filteredCurrentChatAttachments"
|
|
@error="onImgError"
|
|
@close="onClose"
|
|
/>
|
|
</div>
|
|
</template>
|