feat(mail): delay or disable automatic mark message as read

Fixes #1585
This commit is contained in:
Francis Lachapelle
2021-12-07 09:55:13 -05:00
parent 30040ba590
commit 4eed98d58d
14 changed files with 129 additions and 12 deletions
@@ -132,6 +132,7 @@
_this.flags.splice(i, 1,'_' + flag);
}
});
this.isread = !!this.isread;
};
/**
@@ -540,6 +541,31 @@
return Message.$$resource.post(this.$mailbox.$id(), 'addOrRemoveLabel', data);
};
/**
* @function toggleRead
* @memberof Message.prototype
* @desc Toggle message unseen status
* @returns a promise of the HTTP operation
*/
Message.prototype.toggleRead = function() {
var _this = this;
if (this.isread)
return Message.$$resource.fetch(this.$absolutePath(), 'markMessageUnread').then(function() {
Message.$timeout(function() {
_this.isread = false;
_this.$mailbox.unseenCount++;
});
});
else
return Message.$$resource.fetch(this.$absolutePath(), 'markMessageRead').then(function() {
Message.$timeout(function() {
_this.isread = true;
_this.$mailbox.unseenCount--;
});
});
};
/**
* @function $imipAction
* @memberof Message.prototype
@@ -664,13 +690,16 @@
var _this = this, futureMessageData;
if (options && options.useCache && this.$futureMessageData) {
// The message has already been fetched.
if (!this.isread) {
Message.$$resource.fetch(this.$absolutePath(), 'markMessageRead').then(function() {
Message.$timeout(function() {
_this.isread = true;
_this.$mailbox.unseenCount--;
});
});
if (Message.$Preferences.defaults.SOGoMailAutoMarkAsReadDelay > -1)
// Automatically mark message as read
_this.$markAsReadPromise = Message.$timeout(function() {
Message.$$resource.fetch(_this.$absolutePath(), 'markMessageRead').then(function() {
_this.isread = true;
_this.$mailbox.unseenCount--;
});
}, Message.$Preferences.defaults.SOGoMailAutoMarkAsReadDelay * 1000);
}
return this;
}
@@ -865,7 +894,18 @@
// Resolve and expose the promise
this.$futureMessageData = futureMessageData.then(function(data) {
// Calling $timeout will force Angular to refresh the view
if (_this.isread === 0) {
if (!data.isRead) {
if (Message.$Preferences.defaults.SOGoMailAutoMarkAsReadDelay > -1)
// Automatically mark message as read
_this.$markAsReadPromise = Message.$timeout(function() {
Message.$$resource.fetch(_this.$absolutePath(), 'markMessageRead').then(function() {
_this.isread = true;
_this.$mailbox.unseenCount--;
});
}, Message.$Preferences.defaults.SOGoMailAutoMarkAsReadDelay * 1000);
}
else if (!_this.isread) {
// Message as already been marked read on the server
_this.isread = true;
_this.$mailbox.unseenCount--;
}
@@ -98,6 +98,9 @@
_.forEach(hotkeys, function(key) {
sgHotkeys.deregisterHotkey(key);
});
// Cancel automatic mark as read
if (vm.message.$markAsReadPromise)
vm.service.$timeout.cancel(vm.message.$markAsReadPromise);
});
}; // $onInit
@@ -53,6 +53,13 @@
if (data.SOGoRememberLastModule)
data.SOGoLoginModule = "Last";
data.SOGoMailAutoMarkAsReadDelay = parseInt(data.SOGoMailAutoMarkAsReadDelay) || 0;
data.SOGoMailAutoMarkAsReadEnabled = (data.SOGoMailAutoMarkAsReadDelay >= 0);
if (data.SOGoMailAutoMarkAsReadDelay > 0)
data.SOGoMailAutoMarkAsReadMode = 'delay';
else
data.SOGoMailAutoMarkAsReadMode = 'immediate';
// Mail editor autosave is a number of minutes or 0 if disabled
data.SOGoMailAutoSave = parseInt(data.SOGoMailAutoSave) || 0;
@@ -724,6 +731,15 @@
// Don't push locale definition
delete preferences.defaults.locale;
if (preferences.defaults.SOGoMailAutoMarkAsReadEnabled) {
if (preferences.defaults.SOGoMailAutoMarkAsReadMode == 'immediate')
preferences.defaults.SOGoMailAutoMarkAsReadDelay = 0;
} else {
preferences.defaults.SOGoMailAutoMarkAsReadDelay = -1;
}
delete preferences.defaults.SOGoMailAutoMarkAsReadEnabled;
delete preferences.defaults.SOGoMailAutoMarkAsReadMode;
// Merge back mail labels keys and values
preferences.defaults.SOGoMailLabelsColors = {};
_.forEach(preferences.defaults.SOGoMailLabelsColorsKeys, function(key, i) {
@@ -25,6 +25,7 @@
$mdConstant.KEY_CODE.COMMA,
$mdConstant.KEY_CODE.SEMICOLON
];
this.mailAutoMarkAsReadDelay = Preferences.defaults.SOGoMailAutoMarkAsReadEnabled ? Preferences.defaults.SOGoMailAutoMarkAsReadDelay : 5;
// Set alternate avatar in User service
if (Preferences.defaults.SOGoAlternateAvatar)
@@ -107,6 +108,10 @@
form.$setDirty();
};
this.onMailAutoMarkAsReadDelay = function() {
this.preferences.defaults.SOGoMailAutoMarkAsReadDelay = this.mailAutoMarkAsReadDelay;
};
this.addMailAccount = function(ev, form) {
var account, index;