fix(mail): Restore scroll position when refreshing emails

This commit is contained in:
smizrahi
2024-07-19 11:39:28 +02:00
parent ef88039a4a
commit 9d71be9c45
3 changed files with 31 additions and 5 deletions

View File

@@ -31,11 +31,12 @@
* @desc The factory we'll use to register with Angular
* @returns the Mailbox constructor
*/
Mailbox.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Message', 'Acl', 'Preferences', 'sgMailbox_PRELOAD', 'sgMailbox_BATCH_DELETE_LIMIT', function($q, $timeout, $log, Settings, Resource, Message, Acl, Preferences, PRELOAD, BATCH_DELETE_LIMIT) {
Mailbox.$factory = ['$q', '$timeout', '$log', '$rootScope', 'sgSettings', 'Resource', 'Message', 'Acl', 'Preferences', 'sgMailbox_PRELOAD', 'sgMailbox_BATCH_DELETE_LIMIT', function ($q, $timeout, $log, $rootScope, Settings, Resource, Message, Acl, Preferences, PRELOAD, BATCH_DELETE_LIMIT) {
angular.extend(Mailbox, {
$q: $q,
$timeout: $timeout,
$log: $log,
$rootScope: $rootScope,
$$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()),
$Message: Message,
$$Acl: Acl,
@@ -1104,6 +1105,7 @@
* @returns a promise of the HTTP operation
*/
Mailbox.prototype.$unwrap = function(futureMailboxData) {
Mailbox.$rootScope.$broadcast('beforeListRefresh');
var _this = this,
deferred = Mailbox.$q.defer();
@@ -1226,6 +1228,7 @@
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
_this.$isLoading = false;
Mailbox.$rootScope.$broadcast('listRefreshed');
deferred.resolve(_this.$messages);
});
}, function(data) {

View File

@@ -17,11 +17,12 @@
* @desc The factory we'll use to register with Angular
* @returns the VirtualMailbox constructor
*/
VirtualMailbox.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Message', 'Mailbox', 'sgMailbox_PRELOAD', function($q, $timeout, $log, Settings, Resource, Mailbox, Message, PRELOAD) {
VirtualMailbox.$factory = ['$q', '$timeout', '$log', '$rootScope', 'sgSettings', 'Resource', 'Message', 'Mailbox', 'sgMailbox_PRELOAD', function ($q, $timeout, $log, $rootScope, Settings, Resource, Mailbox, Message, PRELOAD) {
angular.extend(VirtualMailbox, {
$q: $q,
$timeout: $timeout,
$log: $log,
$rootScope: $rootScope,
$$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()),
$Message: Message,
selectedFolder: null,

View File

@@ -22,10 +22,10 @@
/**
* @ngInject
*/
sgMessageListItemController.$inject = ['$scope', '$element', 'Mailbox'];
function sgMessageListItemController($scope, $element, Mailbox) {
sgMessageListItemController.$inject = ['$scope', '$element', '$timeout', 'Mailbox'];
function sgMessageListItemController($scope, $element, $timeout, Mailbox) {
var $ctrl = this;
var scrollPosition = 0;
this.$onInit = function () {
var watchedAttrs = ['uid', 'isread', 'isflagged', 'flags', 'loading'];
@@ -77,6 +77,28 @@
element.classList.add('ng-hide');
};
// The following functions are used to store and restore the scroll position of the message list
// Position is stored and restored through the Mailbox service using broadcasting
function storeScrollPosition() {
if ($element.parent()[0] && $element.parent()[0].parentElement && $element.parent()[0].parentElement.parentElement)
scrollPosition = $element.parent()[0].parentElement.parentElement.scrollTop;
}
function restoreScrollPosition() {
$timeout(function () {
if ($element.parent()[0] && $element.parent()[0].parentElement && $element.parent()[0].parentElement.parentElement)
$element.parent()[0].parentElement.parentElement.scrollTop = scrollPosition;
}, 0);
}
$scope.$on('listRefreshed', function () {
restoreScrollPosition();
});
$scope.$on('beforeListRefresh', function () {
storeScrollPosition();
});
}