-
-
-
-
-
@@ -74,6 +112,9 @@ import {
hasPressedArrowRightKey,
} from 'shared/helpers/KeyboardHelpers';
import eventListenerMixins from 'shared/mixins/eventListenerMixins';
+import timeMixin from 'dashboard/mixins/time';
+
+import Thumbnail from 'dashboard/components/widgets/Thumbnail';
const ALLOWED_FILE_TYPES = {
IMAGE: 'image',
@@ -82,7 +123,10 @@ const ALLOWED_FILE_TYPES = {
};
export default {
- mixins: [eventListenerMixins, clickaway],
+ components: {
+ Thumbnail,
+ },
+ mixins: [eventListenerMixins, clickaway, timeMixin],
props: {
show: {
type: Boolean,
@@ -99,11 +143,11 @@ export default {
},
data() {
return {
- attachmentSrc: '',
+ activeAttachment: {},
activeFileType: '',
activeImageIndex:
this.allAttachments.findIndex(
- attachment => attachment.id === this.attachment.id
+ attachment => attachment.message_id === this.attachment.message_id
) || 0,
};
},
@@ -111,6 +155,13 @@ export default {
hasMoreThanOneAttachment() {
return this.allAttachments.length > 1;
},
+ readableTime() {
+ if (!this.activeAttachment.created_at) return '';
+ return this.messageTimestamp(
+ this.activeAttachment.created_at,
+ 'LLL d yyyy, h:mm a'
+ );
+ },
isImage() {
return this.activeFileType === ALLOWED_FILE_TYPES.IMAGE;
},
@@ -120,6 +171,14 @@ export default {
isAudio() {
return this.activeFileType === ALLOWED_FILE_TYPES.AUDIO;
},
+ senderDetails() {
+ const { name, available_name: availableName, avatar_url, thumbnail } =
+ this.activeAttachment?.sender || this.attachment?.sender;
+ return {
+ name: name || availableName,
+ avatar: thumbnail || avatar_url,
+ };
+ },
},
mounted() {
this.setImageAndVideoSrc(this.attachment);
@@ -140,7 +199,7 @@ export default {
if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) {
return;
}
- this.attachmentSrc = attachment.data_url;
+ this.activeAttachment = attachment;
this.activeFileType = type;
},
onKeyDownHandler(e) {
@@ -158,17 +217,83 @@ export default {
);
}
},
+ onClickDownload() {
+ const { file_type: type, data_url: url } = this.activeAttachment;
+ if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) {
+ return;
+ }
+ const link = document.createElement('a');
+ link.href = url;
+ link.download = `attachment.${type}`;
+ link.click();
+ },
},
};