From 1f6bbc1044e8c4f715b96b1b95bfb0eef888e7a3 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Tue, 20 Aug 2024 14:51:35 +0200 Subject: [PATCH] fix(mail): Fix issue where unread counter is invalid when whanging folder. Fixes #6001. --- .../js/Mailer/Mailbox.service.js | 6 +++++ .../js/Mailer/sgMailboxListItem.directive.js | 23 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/UI/WebServerResources/js/Mailer/Mailbox.service.js b/UI/WebServerResources/js/Mailer/Mailbox.service.js index 69b81ffbb1..7dca6d67a7 100644 --- a/UI/WebServerResources/js/Mailer/Mailbox.service.js +++ b/UI/WebServerResources/js/Mailer/Mailbox.service.js @@ -1033,11 +1033,17 @@ */ Mailbox.prototype.$reset = function(options) { var _this = this; + var account; angular.forEach(this.$shadowData, function(value, key) { delete _this[key]; }); + account = Object.assign({}, _this.$account) angular.extend(this, this.$shadowData); this.$shadowData = this.$omit(); + this.account = account; + if (options && options.unseenCount) { + this.unseenCount = options.unseenCount; + } if (options && options.filter) { this.$messages = []; this.$visibleMessages = []; diff --git a/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js b/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js index 940908b768..08a4b5be3d 100644 --- a/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js +++ b/UI/WebServerResources/js/Mailer/sgMailboxListItem.directive.js @@ -53,8 +53,8 @@ /** * @ngInject */ - sgMailboxListItemController.$inject = ['$scope', '$rootScope', '$element', '$state', '$timeout', '$mdToast', '$mdPanel', '$mdMedia', '$mdSidenav', 'sgConstant', 'Dialog', 'Mailbox', 'encodeUriFilter']; - function sgMailboxListItemController($scope, $rootScope, $element, $state, $timeout, $mdToast, $mdPanel, $mdMedia, $mdSidenav, sgConstant, Dialog, Mailbox, encodeUriFilter) { + sgMailboxListItemController.$inject = ['$scope', '$rootScope', '$element', '$state', '$timeout', '$mdToast', '$mdPanel', '$mdMedia', '$mdSidenav', 'sgConstant', 'Dialog', 'Mailbox', 'encodeUriFilter', '$window', 'Account']; + function sgMailboxListItemController($scope, $rootScope, $element, $state, $timeout, $mdToast, $mdPanel, $mdMedia, $mdSidenav, sgConstant, Dialog, Mailbox, encodeUriFilter, $window, Account) { var $ctrl = this; @@ -87,13 +87,20 @@ if (this.editMode || this.mailbox == Mailbox.selectedFolder || this.mailbox.isNoSelect()) return; - this.mailbox.setHighlightWords([]); - if (Mailbox.$virtualMode) { - Mailbox.$virtualMode = false; - Mailbox.$virtualPath = false; - Mailbox.selectedFolder.$reset({ filter: true }); + this.mailbox.setHighlightWords([]); + + if (Mailbox.selectedFolder) { + if (Mailbox.$virtualMode) { + Mailbox.$virtualMode = false; + Mailbox.$virtualPath = false; + $rootScope.$broadcast('resetMailAdvancedSearchPanel'); // Reset advanced search panel (broadcast event to MailboxesController) + if (Mailbox.selectedFolder.$mailboxes && Mailbox.selectedFolder.$mailboxes.length > 0) { + Mailbox.selectedFolder.$reset({ filter: true, unseenCount: Mailbox.selectedFolder.$mailboxes[0].unseenCount }); + } + } else { + Mailbox.selectedFolder.$reset({ filter: true, unseenCount: Mailbox.selectedFolder.unseenCount }); + } } - $rootScope.$broadcast('resetMailAdvancedSearchPanel'); // Reset advanced search panel (broadcast event to MailboxesController) this.accountController.selectFolder(this); if ($event) {