2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2019-08-25 14:29:28 +00:00
|
|
|
<div
|
|
|
|
class="conversation"
|
|
|
|
:class="{ active: isActiveChat, 'unread-chat': hasUnread }"
|
|
|
|
@click="cardClick(chat)"
|
|
|
|
>
|
|
|
|
<Thumbnail
|
2020-01-13 05:47:03 +00:00
|
|
|
v-if="!hideThumbnail"
|
2020-06-02 17:29:02 +00:00
|
|
|
:src="currentContact.thumbnail"
|
2020-07-04 14:16:17 +00:00
|
|
|
:badge="chatMetadata.channel"
|
2019-08-25 14:29:28 +00:00
|
|
|
class="columns"
|
2020-06-02 17:29:02 +00:00
|
|
|
:username="currentContact.name"
|
2020-07-04 06:12:47 +00:00
|
|
|
:status="currentContact.availability_status"
|
2019-10-29 18:06:21 +00:00
|
|
|
size="40px"
|
2019-08-25 14:29:28 +00:00
|
|
|
/>
|
2019-08-14 09:48:44 +00:00
|
|
|
<div class="conversation--details columns">
|
2019-08-25 14:29:28 +00:00
|
|
|
<h4 class="conversation--user">
|
2020-06-02 17:29:02 +00:00
|
|
|
{{ currentContact.name }}
|
2019-08-25 14:29:28 +00:00
|
|
|
<span
|
2020-01-13 05:47:03 +00:00
|
|
|
v-if="!hideInboxName && isInboxNameVisible"
|
2019-08-25 14:29:28 +00:00
|
|
|
v-tooltip.bottom="inboxName(chat.inbox_id)"
|
|
|
|
class="label"
|
|
|
|
>
|
|
|
|
{{ inboxName(chat.inbox_id) }}
|
|
|
|
</span>
|
|
|
|
</h4>
|
2020-06-14 13:00:36 +00:00
|
|
|
<p v-if="lastMessageInChat" class="conversation--message">
|
2020-07-03 17:55:33 +00:00
|
|
|
<i v-if="messageByAgent" class="ion-ios-undo message-from-agent"></i>
|
2020-06-14 13:00:36 +00:00
|
|
|
<span v-if="lastMessageInChat.content">
|
|
|
|
{{ lastMessageInChat.content }}
|
|
|
|
</span>
|
|
|
|
<span v-else-if="!lastMessageInChat.attachments">{{ ` ` }}</span>
|
|
|
|
<span v-else>
|
|
|
|
<i :class="`small-icon ${this.$t(`${attachmentIconKey}.ICON`)}`"></i>
|
|
|
|
{{ this.$t(`${attachmentIconKey}.CONTENT`) }}
|
|
|
|
</span>
|
|
|
|
</p>
|
2019-08-14 09:48:44 +00:00
|
|
|
<div class="conversation--meta">
|
2019-08-25 14:29:28 +00:00
|
|
|
<span class="timestamp">
|
2020-06-14 13:00:36 +00:00
|
|
|
{{ dynamicTime(chat.timestamp) }}
|
2019-08-25 14:29:28 +00:00
|
|
|
</span>
|
2019-08-14 09:48:44 +00:00
|
|
|
<span class="unread">{{ getUnreadCount }}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { mapGetters } from 'vuex';
|
2020-07-03 17:55:33 +00:00
|
|
|
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
import Thumbnail from '../Thumbnail';
|
|
|
|
import conversationMixin from '../../../mixins/conversations';
|
|
|
|
import timeMixin from '../../../mixins/time';
|
|
|
|
import router from '../../../routes';
|
2020-02-22 08:54:51 +00:00
|
|
|
import { frontendURL, conversationUrl } from '../../../helper/URLHelper';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Thumbnail,
|
|
|
|
},
|
|
|
|
|
2019-08-25 14:29:28 +00:00
|
|
|
mixins: [timeMixin, conversationMixin],
|
|
|
|
props: {
|
2020-06-25 15:34:03 +00:00
|
|
|
activeLabel: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-08-25 14:29:28 +00:00
|
|
|
chat: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {},
|
|
|
|
},
|
2020-01-13 05:47:03 +00:00
|
|
|
hideInboxName: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
hideThumbnail: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
2019-12-28 16:26:42 +00:00
|
|
|
inboxesList: 'inboxes/getInboxes',
|
2019-08-14 09:48:44 +00:00
|
|
|
activeInbox: 'getSelectedInbox',
|
2020-03-09 17:57:10 +00:00
|
|
|
currentUser: 'getCurrentUser',
|
2020-05-26 18:06:42 +00:00
|
|
|
accountId: 'getCurrentAccountId',
|
2019-08-14 09:48:44 +00:00
|
|
|
}),
|
|
|
|
|
2020-07-04 14:16:17 +00:00
|
|
|
chatMetadata() {
|
|
|
|
return this.chat.meta;
|
|
|
|
},
|
|
|
|
|
2020-06-02 17:29:02 +00:00
|
|
|
currentContact() {
|
|
|
|
return this.$store.getters['contacts/getContact'](
|
2020-07-04 14:16:17 +00:00
|
|
|
this.chatMetadata.sender.id
|
2020-06-02 17:29:02 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2020-06-14 13:00:36 +00:00
|
|
|
attachmentIconKey() {
|
|
|
|
const lastMessage = this.lastMessageInChat;
|
|
|
|
const [{ file_type: fileType } = {}] = lastMessage.attachments;
|
|
|
|
return `CHAT_LIST.ATTACHMENTS.${fileType}`;
|
|
|
|
},
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
isActiveChat() {
|
|
|
|
return this.currentChat.id === this.chat.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
getUnreadCount() {
|
|
|
|
return this.unreadMessagesCount(this.chat);
|
|
|
|
},
|
|
|
|
|
|
|
|
hasUnread() {
|
|
|
|
return this.getUnreadCount > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
isInboxNameVisible() {
|
|
|
|
return !this.activeInbox;
|
|
|
|
},
|
2020-06-02 17:29:02 +00:00
|
|
|
|
|
|
|
lastMessageInChat() {
|
|
|
|
return this.lastMessage(this.chat);
|
|
|
|
},
|
2020-07-03 17:55:33 +00:00
|
|
|
|
|
|
|
messageByAgent() {
|
|
|
|
const lastMessage = this.lastMessageInChat;
|
|
|
|
const { message_type: messageType } = lastMessage;
|
|
|
|
return messageType === MESSAGE_TYPE.OUTGOING;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
cardClick(chat) {
|
2020-02-22 08:54:51 +00:00
|
|
|
const { activeInbox } = this;
|
2020-06-25 15:34:03 +00:00
|
|
|
const path = conversationUrl({
|
|
|
|
accountId: this.accountId,
|
|
|
|
activeInbox,
|
|
|
|
id: chat.id,
|
|
|
|
label: this.activeLabel,
|
|
|
|
});
|
2020-02-22 08:54:51 +00:00
|
|
|
router.push({ path: frontendURL(path) });
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
inboxName(inboxId) {
|
2019-12-28 16:26:42 +00:00
|
|
|
const stateInbox = this.$store.getters['inboxes/getInbox'](inboxId);
|
|
|
|
return stateInbox.name || '';
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|