2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2022-11-03 05:13:12 +00:00
|
|
|
<div class="conversation--container" :class="colorSchemeClass">
|
2020-05-04 17:37:56 +00:00
|
|
|
<div class="conversation-wrap" :class="{ 'is-typing': isAgentTyping }">
|
2019-12-11 15:27:06 +00:00
|
|
|
<div v-if="isFetchingList" class="message--loader">
|
2022-06-10 13:59:52 +00:00
|
|
|
<spinner />
|
2019-12-11 15:27:06 +00:00
|
|
|
</div>
|
2020-05-04 17:37:56 +00:00
|
|
|
<div
|
|
|
|
v-for="groupedMessage in groupedMessages"
|
|
|
|
:key="groupedMessage.date"
|
|
|
|
class="messages-wrap"
|
|
|
|
>
|
2022-06-10 13:59:52 +00:00
|
|
|
<date-separator :date="groupedMessage.date" />
|
2020-05-04 17:37:56 +00:00
|
|
|
<chat-message
|
2019-12-15 18:23:04 +00:00
|
|
|
v-for="message in groupedMessage.messages"
|
2019-12-14 18:36:01 +00:00
|
|
|
:key="message.id"
|
|
|
|
:message="message"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-05-04 17:37:56 +00:00
|
|
|
<agent-typing-bubble v-if="isAgentTyping" />
|
2019-11-12 04:39:24 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-10-29 07:20:54 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import ChatMessage from 'widget/components/ChatMessage.vue';
|
2020-05-04 17:37:56 +00:00
|
|
|
import AgentTypingBubble from 'widget/components/AgentTypingBubble.vue';
|
2019-12-14 18:36:01 +00:00
|
|
|
import DateSeparator from 'shared/components/DateSeparator.vue';
|
2019-12-11 15:27:06 +00:00
|
|
|
import Spinner from 'shared/components/Spinner.vue';
|
2022-11-03 05:13:12 +00:00
|
|
|
import darkModeMixin from 'widget/mixins/darkModeMixin';
|
|
|
|
|
2019-12-11 15:27:06 +00:00
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ConversationWrap',
|
|
|
|
components: {
|
|
|
|
ChatMessage,
|
2020-05-04 17:37:56 +00:00
|
|
|
AgentTypingBubble,
|
2019-12-14 18:36:01 +00:00
|
|
|
DateSeparator,
|
2019-12-11 15:27:06 +00:00
|
|
|
Spinner,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2022-11-03 05:13:12 +00:00
|
|
|
mixins: [darkModeMixin],
|
2019-10-29 07:20:54 +00:00
|
|
|
props: {
|
2020-11-10 09:55:26 +00:00
|
|
|
groupedMessages: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2019-12-11 15:27:06 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
previousScrollHeight: 0,
|
|
|
|
previousConversationSize: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
earliestMessage: 'conversation/getEarliestMessage',
|
|
|
|
allMessagesLoaded: 'conversation/getAllMessagesLoaded',
|
|
|
|
isFetchingList: 'conversation/getIsFetchingList',
|
|
|
|
conversationSize: 'conversation/getConversationSize',
|
2020-05-04 17:37:56 +00:00
|
|
|
isAgentTyping: 'conversation/getIsAgentTyping',
|
2019-12-11 15:27:06 +00:00
|
|
|
}),
|
2022-11-03 05:13:12 +00:00
|
|
|
colorSchemeClass() {
|
|
|
|
return `${this.darkMode === 'light' ? 'light' : 'dark'}`;
|
|
|
|
},
|
2019-12-11 15:27:06 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
allMessagesLoaded() {
|
|
|
|
this.previousScrollHeight = 0;
|
|
|
|
},
|
|
|
|
},
|
2019-11-09 11:42:31 +00:00
|
|
|
mounted() {
|
2019-12-11 15:27:06 +00:00
|
|
|
this.$el.addEventListener('scroll', this.handleScroll);
|
2019-11-09 11:42:31 +00:00
|
|
|
this.scrollToBottom();
|
|
|
|
},
|
|
|
|
updated() {
|
2019-12-11 15:27:06 +00:00
|
|
|
if (this.previousConversationSize !== this.conversationSize) {
|
|
|
|
this.previousConversationSize = this.conversationSize;
|
|
|
|
this.scrollToBottom();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
this.$el.removeEventListener('scroll', this.handleScroll);
|
2019-11-09 11:42:31 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-12-11 15:27:06 +00:00
|
|
|
...mapActions('conversation', ['fetchOldConversations']),
|
2019-11-09 11:42:31 +00:00
|
|
|
scrollToBottom() {
|
|
|
|
const container = this.$el;
|
2019-12-11 15:27:06 +00:00
|
|
|
container.scrollTop = container.scrollHeight - this.previousScrollHeight;
|
|
|
|
this.previousScrollHeight = 0;
|
|
|
|
},
|
|
|
|
handleScroll() {
|
|
|
|
if (
|
|
|
|
this.isFetchingList ||
|
|
|
|
this.allMessagesLoaded ||
|
|
|
|
!this.conversationSize
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$el.scrollTop < 100) {
|
|
|
|
this.fetchOldConversations({ before: this.earliestMessage.id });
|
|
|
|
this.previousScrollHeight = this.$el.scrollHeight;
|
|
|
|
}
|
2019-11-09 11:42:31 +00:00
|
|
|
},
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
|
|
|
</script>
|
2019-11-12 04:39:24 +00:00
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2020-03-16 06:38:40 +00:00
|
|
|
@import '~widget/assets/scss/variables.scss';
|
|
|
|
@import '~widget/assets/scss/mixins.scss';
|
2019-11-12 04:39:24 +00:00
|
|
|
|
|
|
|
.conversation--container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex: 1;
|
|
|
|
overflow-y: auto;
|
2022-04-08 05:24:51 +00:00
|
|
|
color-scheme: light dark;
|
2022-11-03 05:13:12 +00:00
|
|
|
|
|
|
|
&.light {
|
|
|
|
color-scheme: light;
|
|
|
|
}
|
|
|
|
&.dark {
|
|
|
|
color-scheme: dark;
|
|
|
|
}
|
2019-11-12 04:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.conversation-wrap {
|
|
|
|
flex: 1;
|
2020-05-02 04:17:36 +00:00
|
|
|
padding: $space-large $space-small $space-small $space-small;
|
2019-11-12 04:39:24 +00:00
|
|
|
}
|
2019-12-11 15:27:06 +00:00
|
|
|
|
|
|
|
.message--loader {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2019-11-12 04:39:24 +00:00
|
|
|
</style>
|