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"
|
2019-08-25 14:29:28 +00:00
|
|
|
:src="chat.meta.sender.thumbnail"
|
|
|
|
:badge="chat.meta.sender.channel"
|
|
|
|
class="columns"
|
2019-10-29 18:06:21 +00:00
|
|
|
:username="chat.meta.sender.name"
|
|
|
|
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">
|
|
|
|
{{ chat.meta.sender.name }}
|
|
|
|
<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>
|
|
|
|
<p
|
|
|
|
class="conversation--message"
|
|
|
|
v-html="extractMessageText(lastMessage(chat))"
|
|
|
|
></p>
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
<div class="conversation--meta">
|
2019-08-25 14:29:28 +00:00
|
|
|
<span class="timestamp">
|
|
|
|
{{ dynamicTime(lastMessage(chat).created_at) }}
|
|
|
|
</span>
|
2019-08-14 09:48:44 +00:00
|
|
|
<span class="unread">{{ getUnreadCount }}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
/* eslint no-console: 0 */
|
|
|
|
/* eslint no-extra-boolean-cast: 0 */
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import Thumbnail from '../Thumbnail';
|
|
|
|
import getEmojiSVG from '../emoji/utils';
|
|
|
|
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: {
|
|
|
|
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',
|
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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
cardClick(chat) {
|
2020-02-22 08:54:51 +00:00
|
|
|
const { activeInbox } = this;
|
2020-03-09 17:57:10 +00:00
|
|
|
const path = conversationUrl(
|
|
|
|
this.currentUser.account_id,
|
|
|
|
activeInbox,
|
|
|
|
chat.id
|
|
|
|
);
|
2020-02-22 08:54:51 +00:00
|
|
|
router.push({ path: frontendURL(path) });
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
extractMessageText(chatItem) {
|
|
|
|
if (chatItem.content) {
|
|
|
|
return chatItem.content;
|
|
|
|
}
|
|
|
|
let fileType = '';
|
|
|
|
if (chatItem.attachment) {
|
|
|
|
fileType = chatItem.attachment.file_type;
|
|
|
|
} else {
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
const key = `CHAT_LIST.ATTACHMENTS.${fileType}`;
|
|
|
|
return `
|
|
|
|
<i class="${this.$t(`${key}.ICON`)}"></i>
|
|
|
|
${this.$t(`${key}.CONTENT`)}
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
getEmojiSVG,
|
2019-12-28 16:26:42 +00:00
|
|
|
|
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>
|