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">
|
2021-08-02 10:37:30 +00:00
|
|
|
{{ $t('CONVERSATION.SELECT_A_TWEET_TO_REPLY') }}
|
2020-08-11 04:27:42 +00:00
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
{{ $t('CONVERSATION.REPLYING_TO') }}
|
2021-08-02 10:37:30 +00:00
|
|
|
{{ selectedTweet.content || '' }}
|
2020-08-11 04:27:42 +00:00
|
|
|
</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"
|
2021-06-18 14:42:43 +00:00
|
|
|
class="message--read"
|
2019-11-17 07:39:10 +00:00
|
|
|
: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"
|
2021-06-18 14:42:43 +00:00
|
|
|
class="message--unread"
|
2019-11-17 07:39:10 +00:00
|
|
|
:data="message"
|
2020-08-11 04:27:42 +00:00
|
|
|
:is-a-tweet="isATweet"
|
2019-11-17 07:39:10 +00:00
|
|
|
/>
|
|
|
|
</ul>
|
2021-09-01 13:42:22 +00:00
|
|
|
<div
|
|
|
|
class="conversation-footer"
|
|
|
|
:class="{ 'modal-mask': isPopoutReplyBox }"
|
|
|
|
>
|
2020-05-04 17:37:56 +00:00
|
|
|
<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>
|
2021-08-02 10:37:30 +00:00
|
|
|
<reply-box
|
2021-09-01 13:42:22 +00:00
|
|
|
v-on-clickaway="closePopoutReplyBox"
|
2020-05-04 17:37:56 +00:00
|
|
|
:conversation-id="currentChat.id"
|
2021-08-02 10:37:30 +00:00
|
|
|
:is-a-tweet="isATweet"
|
|
|
|
:selected-tweet="selectedTweet"
|
2021-09-01 13:42:22 +00:00
|
|
|
:popout-reply-box="isPopoutReplyBox"
|
|
|
|
@click="showPopoutReplyBox"
|
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';
|
2021-06-18 14:42:43 +00:00
|
|
|
import { calculateScrollTop } from './helpers/scrollTopCalculationHelper';
|
2021-09-01 13:42:22 +00:00
|
|
|
import { isEscape } from 'shared/helpers/KeyboardHelpers';
|
|
|
|
import eventListenerMixins from 'shared/mixins/eventListenerMixins';
|
|
|
|
import { mixin as clickaway } from 'vue-clickaway';
|
2019-11-17 07:39:10 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Message,
|
|
|
|
ReplyBox,
|
|
|
|
},
|
2021-09-01 13:42:22 +00:00
|
|
|
mixins: [conversationMixin, inboxMixin, eventListenerMixins, clickaway],
|
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,
|
2021-09-01 13:42:22 +00:00
|
|
|
isPopoutReplyBox: false,
|
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;
|
2021-08-02 10:37:30 +00:00
|
|
|
const [selectedMessage] = messages.filter(
|
2020-08-11 04:27:42 +00:00
|
|
|
message => message.id === this.selectedTweetId
|
|
|
|
);
|
2021-08-02 10:37:30 +00:00
|
|
|
return selectedMessage || {};
|
2020-08-11 04:27:42 +00:00
|
|
|
}
|
|
|
|
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', () => {
|
2021-08-02 02:33:12 +00:00
|
|
|
this.$nextTick(() => this.scrollToBottom());
|
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: {
|
2021-09-01 13:42:22 +00:00
|
|
|
showPopoutReplyBox() {
|
|
|
|
this.isPopoutReplyBox = !this.isPopoutReplyBox;
|
|
|
|
},
|
|
|
|
closePopoutReplyBox() {
|
|
|
|
this.isPopoutReplyBox = false;
|
|
|
|
},
|
|
|
|
handleKeyEvents(e) {
|
|
|
|
if (isEscape(e)) {
|
|
|
|
this.closePopoutReplyBox();
|
|
|
|
}
|
|
|
|
},
|
2020-08-01 18:06:59 +00:00
|
|
|
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);
|
2021-08-02 02:33:12 +00:00
|
|
|
this.$nextTick(() => 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() {
|
2021-06-18 14:42:43 +00:00
|
|
|
let relevantMessages = [];
|
|
|
|
if (this.getUnreadCount > 0) {
|
|
|
|
// capturing only the unread messages
|
|
|
|
relevantMessages = this.conversationPanel.querySelectorAll(
|
|
|
|
'.message--unread'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// capturing last message from the messages list
|
|
|
|
relevantMessages = Array.from(
|
|
|
|
this.conversationPanel.querySelectorAll('.message--read')
|
|
|
|
).slice(-1);
|
|
|
|
}
|
|
|
|
this.conversationPanel.scrollTop = calculateScrollTop(
|
|
|
|
this.conversationPanel.scrollHeight,
|
|
|
|
this.$el.scrollHeight,
|
|
|
|
relevantMessages
|
|
|
|
);
|
2020-08-01 18:06:59 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
}
|
2021-09-01 13:42:22 +00:00
|
|
|
|
|
|
|
.modal-mask {
|
|
|
|
&::v-deep {
|
|
|
|
.ProseMirror-woot-style {
|
|
|
|
max-height: 40rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reply-box {
|
|
|
|
border: 1px solid var(--color-border);
|
|
|
|
max-width: 120rem;
|
|
|
|
width: 70%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reply-box .reply-box__top {
|
|
|
|
position: relative;
|
|
|
|
min-height: 44rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.reply-box__top .input {
|
|
|
|
min-height: 44rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.emoji-dialog {
|
|
|
|
position: fixed;
|
|
|
|
left: unset;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
.emoji-dialog::before {
|
|
|
|
transform: rotate(0deg);
|
|
|
|
left: 5px;
|
|
|
|
bottom: var(--space-minus-slab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-25 17:24:45 +00:00
|
|
|
</style>
|