2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2020-05-02 04:17:36 +00:00
|
|
|
<div class="user-message-wrap">
|
|
|
|
<div class="user-message">
|
2021-12-21 06:32:43 +00:00
|
|
|
<div
|
|
|
|
class="message-wrap"
|
|
|
|
:class="{ 'in-progress': isInProgress, 'is-failed': isFailed }"
|
|
|
|
>
|
2020-06-15 08:05:52 +00:00
|
|
|
<user-message-bubble
|
2020-05-02 04:17:36 +00:00
|
|
|
v-if="showTextBubble"
|
|
|
|
:message="message.content"
|
|
|
|
:status="message.status"
|
2020-06-15 08:05:52 +00:00
|
|
|
:widget-color="widgetColor"
|
2020-05-02 04:17:36 +00:00
|
|
|
/>
|
2020-06-15 08:05:52 +00:00
|
|
|
<div
|
|
|
|
v-if="hasAttachments"
|
|
|
|
class="chat-bubble has-attachment user"
|
|
|
|
:style="{ backgroundColor: widgetColor }"
|
|
|
|
>
|
2020-05-02 04:17:36 +00:00
|
|
|
<div v-for="attachment in message.attachments" :key="attachment.id">
|
|
|
|
<image-bubble
|
2021-12-21 06:32:43 +00:00
|
|
|
v-if="attachment.file_type === 'image' && !hasImageError"
|
2020-05-02 04:17:36 +00:00
|
|
|
:url="attachment.data_url"
|
2022-06-23 13:47:46 +00:00
|
|
|
:thumb="attachment.data_url"
|
2020-05-02 04:17:36 +00:00
|
|
|
:readable-time="readableTime"
|
2021-12-21 06:32:43 +00:00
|
|
|
@error="onImageLoadError"
|
|
|
|
/>
|
|
|
|
<file-bubble
|
|
|
|
v-else
|
|
|
|
:url="attachment.data_url"
|
|
|
|
:is-in-progress="isInProgress"
|
2022-12-14 23:21:20 +00:00
|
|
|
:widget-color="widgetColor"
|
2020-05-02 04:17:36 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2020-04-17 15:45:20 +00:00
|
|
|
</div>
|
2021-12-21 06:32:43 +00:00
|
|
|
<div
|
|
|
|
v-if="isFailed"
|
|
|
|
class="flex justify-end align-middle px-4 py-2 text-red-700"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
v-if="!hasAttachments"
|
|
|
|
:title="$t('COMPONENTS.MESSAGE_BUBBLE.RETRY')"
|
|
|
|
class="inline-flex justify-center items-center ml-2"
|
|
|
|
@click="retrySendMessage"
|
|
|
|
>
|
|
|
|
<fluent-icon icon="arrow-clockwise" size="14" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-03-30 06:45:06 +00:00
|
|
|
</div>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-03-30 06:45:06 +00:00
|
|
|
import UserMessageBubble from 'widget/components/UserMessageBubble';
|
|
|
|
import ImageBubble from 'widget/components/ImageBubble';
|
2021-12-21 06:32:43 +00:00
|
|
|
import FluentIcon from 'shared/components/FluentIcon/Index';
|
2020-04-02 06:58:38 +00:00
|
|
|
import FileBubble from 'widget/components/FileBubble';
|
2020-03-30 06:45:06 +00:00
|
|
|
import timeMixin from 'dashboard/mixins/time';
|
2021-07-15 08:57:37 +00:00
|
|
|
import messageMixin from '../mixins/messageMixin';
|
2020-06-15 08:05:52 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'UserMessage',
|
|
|
|
components: {
|
|
|
|
UserMessageBubble,
|
2020-03-30 06:45:06 +00:00
|
|
|
ImageBubble,
|
2020-04-02 06:58:38 +00:00
|
|
|
FileBubble,
|
2021-12-21 06:32:43 +00:00
|
|
|
FluentIcon,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2021-07-15 08:57:37 +00:00
|
|
|
mixins: [timeMixin, messageMixin],
|
2019-10-29 07:20:54 +00:00
|
|
|
props: {
|
2020-03-30 06:45:06 +00:00
|
|
|
message: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
2021-12-21 06:32:43 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hasImageError: false,
|
|
|
|
};
|
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
computed: {
|
2020-06-15 08:05:52 +00:00
|
|
|
...mapGetters({
|
|
|
|
widgetColor: 'appConfig/getWidgetColor',
|
|
|
|
}),
|
|
|
|
|
2020-03-30 06:45:06 +00:00
|
|
|
isInProgress() {
|
|
|
|
const { status = '' } = this.message;
|
|
|
|
return status === 'in_progress';
|
|
|
|
},
|
|
|
|
showTextBubble() {
|
|
|
|
const { message } = this;
|
|
|
|
return !!message.content;
|
|
|
|
},
|
|
|
|
readableTime() {
|
|
|
|
const { created_at: createdAt = '' } = this.message;
|
|
|
|
return this.messageStamp(createdAt);
|
2019-11-29 12:12:35 +00:00
|
|
|
},
|
2021-12-21 06:32:43 +00:00
|
|
|
isFailed() {
|
|
|
|
const { status = '' } = this.message;
|
|
|
|
return status === 'failed';
|
|
|
|
},
|
|
|
|
errorMessage() {
|
|
|
|
const { meta } = this.message;
|
|
|
|
return meta
|
|
|
|
? meta.error
|
|
|
|
: this.$t('COMPONENTS.MESSAGE_BUBBLE.ERROR_MESSAGE');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
message() {
|
|
|
|
this.hasImageError = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.hasImageError = false;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async retrySendMessage() {
|
|
|
|
await this.$store.dispatch(
|
|
|
|
'conversation/sendMessageWithData',
|
|
|
|
this.message
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onImageLoadError() {
|
|
|
|
this.hasImageError = true;
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|