diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2021-04-27 21:31:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 21:31:52 +0300 |
commit | 1a42826dc5779fcb7c8f6521b4b139e6fca0be3c (patch) | |
tree | 6fd53d4d4c2ef8b6258cf5c6e00d5785fb60d744 /src | |
parent | 84f3739580ae5319cd0270492c9e509f50363216 (diff) | |
parent | daf3cb9d5a18d5ef67f0f7b58c536f84d2138dda (diff) |
Merge pull request #4969 from nextcloud/enhancement/1400/unread-counter
Reintroduce unread counter in app navigation
Diffstat (limited to 'src')
-rw-r--r-- | src/components/NavigationMailbox.vue | 5 | ||||
-rw-r--r-- | src/service/MessageService.js | 1 | ||||
-rw-r--r-- | src/store/actions.js | 5 | ||||
-rw-r--r-- | src/store/mutations.js | 19 |
4 files changed, 27 insertions, 3 deletions
diff --git a/src/components/NavigationMailbox.vue b/src/components/NavigationMailbox.vue index 29c8248c2..db9ec3b64 100644 --- a/src/components/NavigationMailbox.vue +++ b/src/components/NavigationMailbox.vue @@ -111,7 +111,7 @@ {{ t('mail', 'Delete mailbox') }} </ActionButton> </template> - <AppNavigationCounter v-if="mailbox.unread" slot="counter"> + <AppNavigationCounter v-if="showUnreadCounter" slot="counter"> {{ mailbox.unread }} </AppNavigationCounter> <template slot="extra"> @@ -293,6 +293,9 @@ export default { } return this.mailbox.specialUse.includes('inbox') && this.$store.getters.accounts.length > 2 }, + showUnreadCounter() { + return this.mailbox.unread > 0 && this.filter !== 'starred' + }, }, mounted() { dragEventBus.$on('dragStart', this.onDragStart) diff --git a/src/service/MessageService.js b/src/service/MessageService.js index d7d2da593..0792e1e19 100644 --- a/src/service/MessageService.js +++ b/src/service/MessageService.js @@ -81,6 +81,7 @@ export async function syncEnvelopes(accountId, id, ids, query, init = false) { newMessages: response.data.newMessages.map(amend), changedMessages: response.data.changedMessages.map(amend), vanishedMessages: response.data.vanishedMessages, + stats: response.data.stats, } } catch (e) { throw convertAxiosError(e) diff --git a/src/store/actions.js b/src/store/actions.js index 297dc6f0f..2c2062d9a 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -499,6 +499,11 @@ export default { // Already removed from unified inbox }) + commit('setMailboxUnreadCount', { + id: mailboxId, + unread: syncData.stats.unread, + }) + return syncData.newMessages }) .catch((error) => { diff --git a/src/store/mutations.js b/src/store/mutations.js index 54a6243d5..b3a754c5a 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -201,7 +201,16 @@ export default { Vue.set(existing, 'tags', envelope.tags) }, flagEnvelope(state, { envelope, flag, value }) { - envelope.flags[flag] = value + const mailbox = state.mailboxes[envelope.mailboxId] + if (mailbox && flag === 'seen') { + const unread = mailbox.unread ?? 0 + if (envelope.flags[flag] && !value) { + Vue.set(mailbox, 'unread', unread + 1) + } else if (!envelope.flags[flag] && value) { + Vue.set(mailbox, 'unread', Math.max(unread - 1, 0)) + } + } + Vue.set(envelope.flags, flag, value) }, addTag(state, { tag }) { Vue.set(state.tags, tag.id, tag) @@ -232,6 +241,10 @@ export default { list.splice(idx, 1) } + if (!envelope.seen && mailbox.unread) { + Vue.set(mailbox, 'unread', mailbox.unread - 1) + } + state.accounts[UNIFIED_ACCOUNT_ID].mailboxes .map((mailboxId) => state.mailboxes[mailboxId]) .filter((mb) => mb.specialRole && mb.specialRole === mailbox.specialRole) @@ -297,5 +310,7 @@ export default { const index = account.aliases.findIndex((temp) => aliasId === temp.id) account.aliases[index] = Object.assign({}, account.aliases[index], data) }, - + setMailboxUnreadCount(state, { id, unread }) { + Vue.set(state.mailboxes[id], 'unread', unread ?? 0) + }, } |