mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
feat: Add a placeholder for image attachments in conversations view (#8969)
We analyze an image to get it's height and width. On the frontend, we would show a placeholder with the corresponding width and height until the images are loaded properly. --------- Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
committed by
GitHub
parent
fd993feece
commit
b7a83dcbcd
@@ -577,7 +577,8 @@ export default {
|
|||||||
|
|
||||||
> img,
|
> img,
|
||||||
> video {
|
> video {
|
||||||
@apply rounded-lg;
|
/** ensure that the bubble radius and image radius match*/
|
||||||
|
@apply rounded-[0.4rem];
|
||||||
}
|
}
|
||||||
|
|
||||||
> video {
|
> video {
|
||||||
|
|||||||
@@ -2,20 +2,23 @@
|
|||||||
<div class="message-text__wrap" :class="attachmentTypeClasses">
|
<div class="message-text__wrap" :class="attachmentTypeClasses">
|
||||||
<img
|
<img
|
||||||
v-if="isImage && !isImageError"
|
v-if="isImage && !isImageError"
|
||||||
:src="attachment.data_url"
|
class="bg-woot-200 dark:bg-woot-900"
|
||||||
|
:src="dataUrl"
|
||||||
|
:width="imageWidth"
|
||||||
|
:height="imageHeight"
|
||||||
@click="onClick"
|
@click="onClick"
|
||||||
@error="onImgError"
|
@error="onImgError"
|
||||||
/>
|
/>
|
||||||
<video
|
<video
|
||||||
v-if="isVideo"
|
v-if="isVideo"
|
||||||
:src="attachment.data_url"
|
:src="dataUrl"
|
||||||
muted
|
muted
|
||||||
playsInline
|
playsInline
|
||||||
@error="onImgError"
|
@error="onImgError"
|
||||||
@click="onClick"
|
@click="onClick"
|
||||||
/>
|
/>
|
||||||
<audio v-else-if="isAudio" controls class="skip-context-menu">
|
<audio v-else-if="isAudio" controls class="skip-context-menu">
|
||||||
<source :src="`${attachment.data_url}?t=${Date.now()}`" />
|
<source :src="`${dataUrl}?t=${Date.now()}`" />
|
||||||
</audio>
|
</audio>
|
||||||
<gallery-view
|
<gallery-view
|
||||||
v-if="show"
|
v-if="show"
|
||||||
@@ -31,7 +34,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
import { hasPressedCommand } from 'shared/helpers/KeyboardHelpers';
|
import { hasPressedCommand } from 'shared/helpers/KeyboardHelpers';
|
||||||
|
|
||||||
import GalleryView from '../components/GalleryView.vue';
|
import GalleryView from '../components/GalleryView.vue';
|
||||||
|
|
||||||
const ALLOWED_FILE_TYPES = {
|
const ALLOWED_FILE_TYPES = {
|
||||||
@@ -81,6 +83,15 @@ export default {
|
|||||||
);
|
);
|
||||||
return attachments;
|
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: {
|
watch: {
|
||||||
attachment() {
|
attachment() {
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ class Attachment < ApplicationRecord
|
|||||||
extension: extension,
|
extension: extension,
|
||||||
data_url: file_url,
|
data_url: file_url,
|
||||||
thumb_url: thumb_url,
|
thumb_url: thumb_url,
|
||||||
file_size: file.byte_size
|
file_size: file.byte_size,
|
||||||
|
width: file.metadata[:width],
|
||||||
|
height: file.metadata[:height]
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata[:data_url] = metadata[:thumb_url] = external_url if message.instagram_story_mention?
|
metadata[:data_url] = metadata[:thumb_url] = external_url if message.instagram_story_mention?
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ json.payload @attachments do |attachment|
|
|||||||
json.file_size attachment.push_event_data[:file_size]
|
json.file_size attachment.push_event_data[:file_size]
|
||||||
json.file_type attachment.push_event_data[:file_type]
|
json.file_type attachment.push_event_data[:file_type]
|
||||||
json.extension attachment.push_event_data[:extension]
|
json.extension attachment.push_event_data[:extension]
|
||||||
|
json.width attachment.push_event_data[:width]
|
||||||
|
json.height attachment.push_event_data[:height]
|
||||||
json.created_at attachment.message.created_at.to_i
|
json.created_at attachment.message.created_at.to_i
|
||||||
json.sender attachment.message.sender.push_event_data if attachment.message.sender
|
json.sender attachment.message.sender.push_event_data if attachment.message.sender
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user