2019-11-17 07:39:10 +00:00
|
|
|
<template>
|
2021-03-02 17:14:04 +00:00
|
|
|
<div class="view-box fill-height">
|
2021-04-12 10:45:11 +00:00
|
|
|
<div
|
|
|
|
v-if="!currentChat.can_reply && !isATwilioWhatsappChannel"
|
|
|
|
class="banner messenger-policy--banner"
|
|
|
|
>
|
2020-07-25 17:24:45 +00:00
|
|
|
<span>
|
|
|
|
{{ $t('CONVERSATION.CANNOT_REPLY') }}
|
|
|
|
<a
|
2021-04-12 10:45:11 +00:00
|
|
|
:href="facebookReplyPolicy"
|
2020-07-25 17:24:45 +00:00
|
|
|
rel="noopener noreferrer nofollow"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{{ $t('CONVERSATION.24_HOURS_WINDOW') }}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-04-12 10:45:11 +00:00
|
|
|
<div
|
|
|
|
v-if="!currentChat.can_reply && isATwilioWhatsappChannel"
|
|
|
|
class="banner messenger-policy--banner"
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
{{ $t('CONVERSATION.TWILIO_WHATSAPP_CAN_REPLY') }}
|
|
|
|
<a
|
|
|
|
:href="twilioWhatsAppReplyPolicy"
|
|
|
|
rel="noopener noreferrer nofollow"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{{ $t('CONVERSATION.TWILIO_WHATSAPP_24_HOURS_WINDOW') }}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
2020-08-11 04:27:42 +00:00
|
|
|
|
|
|
|
<div v-if="isATweet" class="banner">
|
|
|
|
<span v-if="!selectedTweetId">
|
|
|
|
{{ $t('CONVERSATION.LAST_INCOMING_TWEET') }}
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
{{ $t('CONVERSATION.REPLYING_TO') }}
|
|
|
|
{{ selectedTweet }}
|
|
|
|
</span>
|
|
|
|
<button
|
|
|
|
v-if="selectedTweetId"
|
|
|
|
class="banner-close-button"
|
|
|
|
@click="removeTweetSelection"
|
|
|
|
>
|
|
|
|
<i v-tooltip="$t('CONVERSATION.REMOVE_SELECTION')" class="ion-close" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2019-11-17 07:39:10 +00:00
|
|
|
<ul class="conversation-panel">
|
|
|
|
<transition name="slide-up">
|
2020-08-01 18:06:59 +00:00
|
|
|
<li class="spinner--container">
|
2019-11-17 07:39:10 +00:00
|
|
|
<span v-if="shouldShowSpinner" class="spinner message" />
|
|
|
|
</li>
|
|
|
|
</transition>
|
|
|
|
<message
|
|
|
|
v-for="message in getReadMessages"
|
|
|
|
:key="message.id"
|
|
|
|
:data="message"
|
2020-08-11 04:27:42 +00:00
|
|
|
:is-a-tweet="isATweet"
|
2019-11-17 07:39:10 +00:00
|
|
|
/>
|
|
|
|
<li v-show="getUnreadCount != 0" class="unread--toast">
|
2020-12-14 19:54:56 +00:00
|
|
|
<span class="text-uppercase">
|
|
|
|
{{ getUnreadCount }}
|
|
|
|
{{
|
|
|
|
getUnreadCount > 1
|
|
|
|
? $t('CONVERSATION.UNREAD_MESSAGES')
|
|
|
|
: $t('CONVERSATION.UNREAD_MESSAGE')
|
|
|
|
}}
|
2019-11-17 07:39:10 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
<message
|
|
|
|
v-for="message in getUnReadMessages"
|
|
|
|
:key="message.id"
|
|
|
|
:data="message"
|
2020-08-11 04:27:42 +00:00
|
|
|
:is-a-tweet="isATweet"
|
2019-11-17 07:39:10 +00:00
|
|
|
/>
|
|
|
|
</ul>
|
2020-05-04 17:37:56 +00:00
|
|
|
<div class="conversation-footer">
|
|
|
|
<div v-if="isAnyoneTyping" class="typing-indicator-wrap">
|
|
|
|
<div class="typing-indicator">
|
|
|
|
{{ typingUserNames }}
|
|
|
|
<img
|
|
|
|
class="gif"
|
|
|
|
src="~dashboard/assets/images/typing.gif"
|
|
|
|
alt="Someone is typing"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ReplyBox
|
|
|
|
:conversation-id="currentChat.id"
|
2020-08-11 04:27:42 +00:00
|
|
|
:in-reply-to="selectedTweetId"
|
2020-08-01 18:06:59 +00:00
|
|
|
@scrollToMessage="scrollToBottom"
|
2020-05-04 17:37:56 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2019-11-17 07:39:10 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
|
|
|
|
import ReplyBox from './ReplyBox';
|
|
|
|
import Message from './Message';
|
|
|
|
import conversationMixin from '../../../mixins/conversations';
|
2020-05-04 17:37:56 +00:00
|
|
|
import { getTypingUsersText } from '../../../helper/commons';
|
2020-08-11 04:27:42 +00:00
|
|
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
2021-04-12 10:45:11 +00:00
|
|
|
import { REPLY_POLICY } from 'shared/constants/links';
|
|
|
|
import inboxMixin from 'shared/mixins/inboxMixin';
|
2019-11-17 07:39:10 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Message,
|
|
|
|
ReplyBox,
|
|
|
|
},
|
2021-04-12 10:45:11 +00:00
|
|
|
mixins: [conversationMixin, inboxMixin],
|
2019-11-17 07:39:10 +00:00
|
|
|
props: {
|
|
|
|
isContactPanelOpen: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoadingPrevious: true,
|
|
|
|
heightBeforeLoad: null,
|
|
|
|
conversationPanel: null,
|
2020-08-11 04:27:42 +00:00
|
|
|
selectedTweetId: null,
|
2019-11-17 07:39:10 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
currentChat: 'getSelectedChat',
|
|
|
|
allConversations: 'getAllConversations',
|
2019-12-28 16:26:42 +00:00
|
|
|
inboxesList: 'inboxes/getInboxes',
|
2019-11-17 07:39:10 +00:00
|
|
|
listLoadingStatus: 'getAllMessagesLoaded',
|
|
|
|
getUnreadCount: 'getUnreadCount',
|
|
|
|
loadingChatList: 'getChatListLoadingStatus',
|
|
|
|
}),
|
2021-04-12 10:45:11 +00:00
|
|
|
inboxId() {
|
|
|
|
return this.currentChat.inbox_id;
|
|
|
|
},
|
|
|
|
inbox() {
|
|
|
|
return this.$store.getters['inboxes/getInbox'](this.inboxId);
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
|
2020-05-04 17:37:56 +00:00
|
|
|
typingUsersList() {
|
|
|
|
const userList = this.$store.getters[
|
|
|
|
'conversationTypingStatus/getUserList'
|
|
|
|
](this.currentChat.id);
|
|
|
|
return userList;
|
|
|
|
},
|
|
|
|
isAnyoneTyping() {
|
|
|
|
const userList = this.typingUsersList;
|
|
|
|
return userList.length !== 0;
|
|
|
|
},
|
|
|
|
typingUserNames() {
|
|
|
|
const userList = this.typingUsersList;
|
|
|
|
|
|
|
|
if (this.isAnyoneTyping) {
|
|
|
|
const userListAsName = getTypingUsersText(userList);
|
|
|
|
return userListAsName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
|
2019-11-17 07:39:10 +00:00
|
|
|
getMessages() {
|
|
|
|
const [chat] = this.allConversations.filter(
|
|
|
|
c => c.id === this.currentChat.id
|
|
|
|
);
|
|
|
|
return chat;
|
|
|
|
},
|
|
|
|
getReadMessages() {
|
|
|
|
const chat = this.getMessages;
|
|
|
|
return chat === undefined ? null : this.readMessages(chat);
|
|
|
|
},
|
|
|
|
getUnReadMessages() {
|
|
|
|
const chat = this.getMessages;
|
|
|
|
return chat === undefined ? null : this.unReadMessages(chat);
|
|
|
|
},
|
|
|
|
shouldShowSpinner() {
|
|
|
|
return (
|
2021-03-20 11:42:36 +00:00
|
|
|
(this.getMessages && this.getMessages.dataFetched === undefined) ||
|
2019-11-17 07:39:10 +00:00
|
|
|
(!this.listLoadingStatus && this.isLoadingPrevious)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldLoadMoreChats() {
|
|
|
|
return !this.listLoadingStatus && !this.isLoadingPrevious;
|
|
|
|
},
|
2020-08-11 04:27:42 +00:00
|
|
|
|
|
|
|
conversationType() {
|
|
|
|
const { additional_attributes: additionalAttributes } = this.currentChat;
|
|
|
|
const type = additionalAttributes ? additionalAttributes.type : '';
|
|
|
|
return type || '';
|
|
|
|
},
|
|
|
|
|
|
|
|
isATweet() {
|
|
|
|
return this.conversationType === 'tweet';
|
|
|
|
},
|
|
|
|
|
|
|
|
selectedTweet() {
|
|
|
|
if (this.selectedTweetId) {
|
|
|
|
const { messages = [] } = this.getMessages;
|
|
|
|
const [selectedMessage = {}] = messages.filter(
|
|
|
|
message => message.id === this.selectedTweetId
|
|
|
|
);
|
|
|
|
return selectedMessage.content || '';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
2021-04-12 10:45:11 +00:00
|
|
|
facebookReplyPolicy() {
|
|
|
|
return REPLY_POLICY.FACEBOOK;
|
|
|
|
},
|
|
|
|
twilioWhatsAppReplyPolicy() {
|
|
|
|
return REPLY_POLICY.TWILIO_WHATSAPP;
|
|
|
|
},
|
2020-08-11 04:27:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
currentChat(newChat, oldChat) {
|
|
|
|
if (newChat.id === oldChat.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.selectedTweetId = null;
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
bus.$on('scrollToMessage', () => {
|
2020-08-01 18:06:59 +00:00
|
|
|
setTimeout(() => this.scrollToBottom(), 0);
|
2019-11-17 07:39:10 +00:00
|
|
|
this.makeMessagesRead();
|
|
|
|
});
|
2020-08-11 04:27:42 +00:00
|
|
|
|
|
|
|
bus.$on(BUS_EVENTS.SET_TWEET_REPLY, selectedTweetId => {
|
|
|
|
this.selectedTweetId = selectedTweetId;
|
|
|
|
});
|
2019-11-17 07:39:10 +00:00
|
|
|
},
|
|
|
|
|
2020-08-01 18:06:59 +00:00
|
|
|
mounted() {
|
|
|
|
this.addScrollListener();
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
|
2020-08-01 18:06:59 +00:00
|
|
|
unmounted() {
|
|
|
|
this.removeScrollListener();
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
|
2020-08-01 18:06:59 +00:00
|
|
|
methods: {
|
|
|
|
addScrollListener() {
|
2019-11-17 07:39:10 +00:00
|
|
|
this.conversationPanel = this.$el.querySelector('.conversation-panel');
|
2020-08-01 18:06:59 +00:00
|
|
|
this.setScrollParams();
|
2019-11-17 07:39:10 +00:00
|
|
|
this.conversationPanel.addEventListener('scroll', this.handleScroll);
|
2020-08-01 18:06:59 +00:00
|
|
|
this.scrollToBottom();
|
2019-11-17 07:39:10 +00:00
|
|
|
this.isLoadingPrevious = false;
|
|
|
|
},
|
2020-08-01 18:06:59 +00:00
|
|
|
removeScrollListener() {
|
|
|
|
this.conversationPanel.removeEventListener('scroll', this.handleScroll);
|
|
|
|
},
|
|
|
|
scrollToBottom() {
|
|
|
|
this.conversationPanel.scrollTop = this.conversationPanel.scrollHeight;
|
|
|
|
},
|
|
|
|
onToggleContactPanel() {
|
2020-08-17 05:55:13 +00:00
|
|
|
this.$emit('contact-panel-toggle');
|
2020-08-01 18:06:59 +00:00
|
|
|
},
|
|
|
|
setScrollParams() {
|
|
|
|
this.heightBeforeLoad = this.conversationPanel.scrollHeight;
|
|
|
|
this.scrollTopBeforeLoad = this.conversationPanel.scrollTop;
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
|
|
|
|
handleScroll(e) {
|
2020-08-01 18:06:59 +00:00
|
|
|
this.setScrollParams();
|
|
|
|
|
2019-11-17 07:39:10 +00:00
|
|
|
const dataFetchCheck =
|
|
|
|
this.getMessages.dataFetched === true && this.shouldLoadMoreChats;
|
|
|
|
if (
|
|
|
|
e.target.scrollTop < 100 &&
|
|
|
|
!this.isLoadingPrevious &&
|
|
|
|
dataFetchCheck
|
|
|
|
) {
|
|
|
|
this.isLoadingPrevious = true;
|
|
|
|
this.$store
|
|
|
|
.dispatch('fetchPreviousMessages', {
|
|
|
|
conversationId: this.currentChat.id,
|
|
|
|
before: this.getMessages.messages[0].id,
|
|
|
|
})
|
|
|
|
.then(() => {
|
2020-08-01 18:06:59 +00:00
|
|
|
const heightDifference =
|
|
|
|
this.conversationPanel.scrollHeight - this.heightBeforeLoad;
|
2019-11-17 07:39:10 +00:00
|
|
|
this.conversationPanel.scrollTop =
|
2020-08-01 18:06:59 +00:00
|
|
|
this.scrollTopBeforeLoad + heightDifference;
|
2019-11-17 07:39:10 +00:00
|
|
|
this.isLoadingPrevious = false;
|
2020-08-01 18:06:59 +00:00
|
|
|
this.setScrollParams();
|
2019-11-17 07:39:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
makeMessagesRead() {
|
2020-08-03 08:10:20 +00:00
|
|
|
this.$store.dispatch('markMessagesRead', { id: this.currentChat.id });
|
2019-11-17 07:39:10 +00:00
|
|
|
},
|
2020-08-11 04:27:42 +00:00
|
|
|
removeTweetSelection() {
|
|
|
|
this.selectedTweetId = null;
|
|
|
|
},
|
2019-11-17 07:39:10 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2020-07-25 17:24:45 +00:00
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2020-08-11 04:27:42 +00:00
|
|
|
.banner {
|
|
|
|
background: var(--b-500);
|
2020-07-25 17:24:45 +00:00
|
|
|
color: var(--white);
|
|
|
|
font-size: var(--font-size-mini);
|
|
|
|
padding: var(--space-slab) var(--space-normal);
|
|
|
|
text-align: center;
|
2020-08-11 04:27:42 +00:00
|
|
|
position: relative;
|
2020-07-25 17:24:45 +00:00
|
|
|
|
|
|
|
a {
|
|
|
|
text-decoration: underline;
|
|
|
|
color: var(--white);
|
|
|
|
font-size: var(--font-size-mini);
|
|
|
|
}
|
2020-08-11 04:27:42 +00:00
|
|
|
|
|
|
|
&.messenger-policy--banner {
|
|
|
|
background: var(--r-400);
|
|
|
|
}
|
|
|
|
|
|
|
|
.banner-close-button {
|
|
|
|
cursor: pointer;
|
|
|
|
margin-left: var(--space--two);
|
|
|
|
color: var(--white);
|
|
|
|
}
|
2020-07-25 17:24:45 +00:00
|
|
|
}
|
2020-08-01 18:06:59 +00:00
|
|
|
|
|
|
|
.spinner--container {
|
|
|
|
min-height: var(--space-jumbo);
|
|
|
|
}
|
2021-03-02 17:14:04 +00:00
|
|
|
|
|
|
|
.view-box.fill-height {
|
|
|
|
height: auto;
|
|
|
|
flex-grow: 1;
|
2021-05-25 07:23:00 +00:00
|
|
|
min-width: 0;
|
2021-03-02 17:14:04 +00:00
|
|
|
}
|
2020-07-25 17:24:45 +00:00
|
|
|
</style>
|