From 30ef55cff4dbb211b73a2f2cb21ef63c0596337b Mon Sep 17 00:00:00 2001 From: silver-it Date: Wed, 6 Mar 2024 22:01:59 +0800 Subject: [PATCH] feat: file attachments for images --- .../views/containers/chatroom/ChatMain.vue | 2 - .../views/containers/chatroom/MessageBase.vue | 4 - .../views/containers/chatroom/SendArea.vue | 4 +- .../file-attachment/ChatAttachmentPreview.vue | 107 +++++++++++++++--- 4 files changed, 95 insertions(+), 22 deletions(-) diff --git a/frontend/views/containers/chatroom/ChatMain.vue b/frontend/views/containers/chatroom/ChatMain.vue index 85cf0b06a1..f1ddc09b1d 100644 --- a/frontend/views/containers/chatroom/ChatMain.vue +++ b/frontend/views/containers/chatroom/ChatMain.vue @@ -118,7 +118,6 @@ import { mapGetters } from 'vuex' import { Vue } from '@common/common.js' import Avatar from '@components/Avatar.vue' import InfiniteLoading from 'vue-infinite-loading' -import Loading from '@components/Loading.vue' import Message from './Message.vue' import MessageInteractive from './MessageInteractive.vue' import MessageNotification from './MessageNotification.vue' @@ -212,7 +211,6 @@ export default ({ ConversationGreetings, Emoticons, InfiniteLoading, - Loading, Message, MessageInteractive, MessageNotification, diff --git a/frontend/views/containers/chatroom/MessageBase.vue b/frontend/views/containers/chatroom/MessageBase.vue index e5a86d3085..90e7821704 100644 --- a/frontend/views/containers/chatroom/MessageBase.vue +++ b/frontend/views/containers/chatroom/MessageBase.vue @@ -202,9 +202,6 @@ export default ({ isMention (o) { return o.type === TextObjectType.Mention }, - isImage (attachment) { - return attachment.attachType === 'image' - }, generateTextObjectsFromText (text) { if (!text) { return [] @@ -253,7 +250,6 @@ export default ({ padding: 0.5rem 1.25rem; } position: relative; - max-height: 100%; &.removed { background-color: $danger_2; diff --git a/frontend/views/containers/chatroom/SendArea.vue b/frontend/views/containers/chatroom/SendArea.vue index 11998cf868..44e1fff517 100644 --- a/frontend/views/containers/chatroom/SendArea.vue +++ b/frontend/views/containers/chatroom/SendArea.vue @@ -245,7 +245,7 @@ import Avatar from '@components/Avatar.vue' import Tooltip from '@components/Tooltip.vue' import ChatAttachmentPreview from './file-attachment/ChatAttachmentPreview.vue' import { makeMentionFromUsername } from '@model/contracts/shared/functions.js' -import { CHATROOM_PRIVACY_LEVEL } from '@model/contracts/shared/constants.js' +import { CHATROOM_PRIVACY_LEVEL, ATTACHMENT_TYPES } from '@model/contracts/shared/constants.js' import { CHAT_ATTACHMENT_SUPPORTED_EXTENSIONS, CHAT_ATTACHMENT_SIZE_LIMIT } from '~/frontend/utils/constants.js' import { OPEN_MODAL, CHATROOM_USER_TYPING, CHATROOM_USER_STOP_TYPING } from '@utils/events.js' import { uniq, throttle, cloneDeep, randomHexString } from '@model/contracts/shared/giLodash.js' @@ -626,7 +626,7 @@ export default ({ extension: fileExt, mimeType: file.type || '', attachmentId: randomHexString(15), - attachType: file.type.match('image/') ? 'image' : 'non-image', + attachType: file.type.match('image/') ? ATTACHMENT_TYPES.IMAGE : ATTACHMENT_TYPES.NON_IMAGE, downloadData: null // NOTE: we can tell if the attachment has been uploaded by seeing if this field is non-null. }) } diff --git a/frontend/views/containers/chatroom/file-attachment/ChatAttachmentPreview.vue b/frontend/views/containers/chatroom/file-attachment/ChatAttachmentPreview.vue index 76144c8c40..4e6ae68752 100644 --- a/frontend/views/containers/chatroom/file-attachment/ChatAttachmentPreview.vue +++ b/frontend/views/containers/chatroom/file-attachment/ChatAttachmentPreview.vue @@ -7,7 +7,7 @@ class='is-download-item' tabindex='0' ) - .c-preview-non-image + .c-preview-non-image(v-if='!shouldPreviewImages') .c-non-image-icon i.icon-file @@ -15,6 +15,17 @@ .c-file-name.has-ellipsis {{ entry.name }} .c-file-ext {{ fileExt(entry) }} + .c-preview-img(v-else) + img( + v-if='preloadedBlobs[entry.attachmentId]' + :src='preloadedBlobs[entry.attachmentId].url' + :alt='entry.name' + ) + .loading-box(v-else) + + .c-attachment-actions-wrapper( + :class='{ "is-for-image": shouldPreviewImages }' + ) .c-attachment-actions tooltip( direction='top' @@ -69,6 +80,7 @@