2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2019-11-12 04:39:24 +00:00
|
|
|
<div class="conversation--container">
|
|
|
|
<div class="conversation-wrap">
|
2019-12-11 15:27:06 +00:00
|
|
|
<div v-if="isFetchingList" class="message--loader">
|
|
|
|
<spinner></spinner>
|
|
|
|
</div>
|
2019-12-15 18:23:04 +00:00
|
|
|
<div v-for="groupedMessage in groupedMessages" :key="groupedMessage.date">
|
|
|
|
<date-separator :date="groupedMessage.date"></date-separator>
|
2019-12-14 18:36:01 +00:00
|
|
|
<ChatMessage
|
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>
|
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';
|
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';
|
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2019-10-29 07:20:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ConversationWrap',
|
|
|
|
components: {
|
|
|
|
ChatMessage,
|
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
|
|
|
},
|
|
|
|
props: {
|
2019-12-15 18:23:04 +00:00
|
|
|
groupedMessages: Array,
|
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',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
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">
|
|
|
|
@import '~widget/assets/scss/woot.scss';
|
|
|
|
|
|
|
|
.conversation--container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex: 1;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.conversation-wrap {
|
|
|
|
flex: 1;
|
|
|
|
padding: $space-large $space-small $zero $space-small;
|
|
|
|
}
|
2019-12-11 15:27:06 +00:00
|
|
|
|
|
|
|
.message--loader {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2019-11-12 04:39:24 +00:00
|
|
|
</style>
|