diff --git a/src/components/LeftSidebar/LeftSidebar.vue b/src/components/LeftSidebar/LeftSidebar.vue
index 6404c612d530..9268825df723 100644
--- a/src/components/LeftSidebar/LeftSidebar.vue
+++ b/src/components/LeftSidebar/LeftSidebar.vue
@@ -121,17 +121,30 @@
-
- -
+
+
+
+
+
+
+
+
+
+
+ {{ t('spreed', 'Clear filter') }}
+
+
+
+
-
-
-
filterFunction(this.isFiltered, conversation)
+ || conversation.hasCall
+ || conversation.token === this.token)
- if (this.isFiltered === 'unread') {
- return this.conversationsList.filter(conversation => conversation.unreadMessages > 0
- || conversation.hasCall || conversation.token === this.$store.getters.getToken())
- }
+ // return empty if it only includes the current conversation without any flags
+ const isNewFilter = this.isPreviousFilter() !== this.isFiltered
+ const validFilteredConversations = filteredConversations.filter((conversation) => filterFunction(this.isFiltered, conversation))
- if (this.isFiltered === 'mentions') {
- return this.conversationsList.filter(conversation => conversation.unreadMention
- || conversation.hasCall
- || (conversation.unreadMessages > 0 && (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE || conversation.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER))
- || conversation.token === this.$store.getters.getToken())
+ return !validFilteredConversations.length && isNewFilter ? [] : filteredConversations
}
return this.conversationsList
@@ -523,18 +556,24 @@ export default {
this.$refs.openConversationsList.showModal()
},
+ isPreviousFilter() {
+ const cachedPreviousFilter = this.previousFilter
+ this.previousFilter = this.isFiltered
+ return cachedPreviousFilter
+ },
+
handleFilter(filter) {
this.isFiltered = filter
-
// Store the active filter
if (filter) {
BrowserStorage.setItem('filterEnabled', filter)
} else {
BrowserStorage.removeItem('filterEnabled')
}
-
// Clear the search input once a filter is active
this.searchText = ''
+ // Initiate the previous filter
+ this.previousFilter = null
},
scrollBottomUnread() {
@@ -927,6 +966,11 @@ export default {
}
+:deep(.empty-content) {
+ text-align: center;
+ margin-top: 10%;
+}
+
.settings-button {
justify-content: flex-start !important;
}
diff --git a/src/utils/conversation.js b/src/utils/conversation.js
new file mode 100644
index 000000000000..b2e62b63d9fa
--- /dev/null
+++ b/src/utils/conversation.js
@@ -0,0 +1,59 @@
+/**
+ * @copyright Copyright (c) 2023
+ *
+ * @author Dorra Jaouad
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ *
+ */
+import { CONVERSATION } from '../constants.js'
+
+/**
+ * check if the conversation has unread messages
+ *
+ * @param {object} conversation conversation object
+ * @return {boolean}
+ */
+export function hasUnreadMessages(conversation) {
+ return conversation.unreadMessages > 0
+}
+
+/**
+ * check if the conversation has unread mentions
+ *
+ * @param {object} conversation conversation object
+ * @return {boolean}
+ */
+export function hasUnreadMentions(conversation) {
+ return conversation.unreadMention
+ || conversation.unreadMentionDirect
+ || (conversation.unreadMessages > 0
+ && (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE || conversation.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER))
+}
+
+/**
+ * apply the active filter
+ *
+ * @param {string} filter the filter option
+ * @param {object} conversation conversation object
+ */
+export function filterFunction(filter, conversation) {
+ if (filter === 'unread') {
+ return hasUnreadMessages(conversation)
+ } else if (filter === 'mentions') {
+ return hasUnreadMentions(conversation)
+ }
+}