diff options
author | Joas Schilling <coding@schilljs.com> | 2020-07-29 16:12:20 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-09-01 09:29:29 +0200 |
commit | 3dd2d0ccf81be61d9aa4b818e50fb6db7f436725 (patch) | |
tree | 8f465fb91035412f3596166363ea72b355cf66cc /src/components/LeftSidebar/ConversationsList/ConversationsList.vue | |
parent | 7809a5f7a8cd98dea4e4910523698c39e70e1540 (diff) |
Move the logic of the conversation list to the left sidebar so all data is handled in one place
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'src/components/LeftSidebar/ConversationsList/ConversationsList.vue')
-rw-r--r-- | src/components/LeftSidebar/ConversationsList/ConversationsList.vue | 84 |
1 files changed, 10 insertions, 74 deletions
diff --git a/src/components/LeftSidebar/ConversationsList/ConversationsList.vue b/src/components/LeftSidebar/ConversationsList/ConversationsList.vue index bbfee0cf5..38631e435 100644 --- a/src/components/LeftSidebar/ConversationsList/ConversationsList.vue +++ b/src/components/LeftSidebar/ConversationsList/ConversationsList.vue @@ -40,10 +40,8 @@ import Conversation from './Conversation' import Hint from '../../Hint' import LoadingPlaceholder from '../../LoadingPlaceholder' -import { fetchConversations } from '../../../services/conversationsService' import { joinConversation, leaveConversation } from '../../../services/participantsService' import { EventBus } from '../../../services/EventBus' -import debounce from 'debounce' export default { name: 'ConversationsList', @@ -57,47 +55,30 @@ export default { type: String, default: '', }, + + conversationsList: { + type: Array, + required: true, + }, + + initialisedConversations: { + type: Boolean, + default: true, + }, }, data() { return { - initialisedConversations: false, isFetchingConversations: false, } }, - computed: { - conversationsList() { - let conversations = this.$store.getters.conversationsList - - if (this.searchText !== '') { - const lowerSearchText = this.searchText.toLowerCase() - conversations = conversations.filter(conversation => conversation.displayName.toLowerCase().indexOf(lowerSearchText) !== -1 || conversation.name.toLowerCase().indexOf(lowerSearchText) !== -1) - } - - return conversations.sort(this.sortConversations) - }, - }, - - beforeMount() { - this.fetchConversations() - }, - mounted() { - /** Refreshes the conversations every 30 seconds */ - window.setInterval(() => { - if (!this.isFetchingConversations) { - this.fetchConversations() - } - }, 30000) - EventBus.$on('routeChange', this.onRouteChange) - EventBus.$on('shouldRefreshConversations', this.debounceFetchConversations) }, beforeDestroy() { EventBus.$off('routeChange', this.onRouteChange) - EventBus.$off('shouldRefreshConversations', this.debounceFetchConversations) }, methods: { @@ -111,51 +92,6 @@ export default { } }, - sortConversations(conversation1, conversation2) { - if (conversation1.isFavorite !== conversation2.isFavorite) { - return conversation1.isFavorite ? -1 : 1 - } - - return conversation2.lastActivity - conversation1.lastActivity - }, - - debounceFetchConversations: debounce(function() { - if (!this.isFetchingConversations) { - this.fetchConversations() - } - }, 3000), - - async fetchConversations() { - this.isFetchingConversations = true - - /** - * Fetches the conversations from the server and then adds them one by one - * to the store. - */ - try { - const conversations = await fetchConversations() - this.initialisedConversations = true - this.$store.dispatch('purgeConversationsStore') - conversations.data.ocs.data.forEach(conversation => { - this.$store.dispatch('addConversation', conversation) - if (conversation.token === this.$store.getters.getToken()) { - this.$store.dispatch('markConversationRead', this.$store.getters.getToken()) - } - }) - /** - * Emits a global event that is used in App.vue to update the page title once the - * ( if the current route is a conversation and once the conversations are received) - */ - EventBus.$emit('conversationsReceived', { - singleConversation: false, - }) - this.isFetchingConversations = false - } catch (error) { - console.debug('Error while fetching conversations: ', error) - this.isFetchingConversations = false - } - }, - // Emit the click event so the search text in the leftsidebar can be reset. handleConversationClick(item) { this.$emit('click-search-result', item.token) |