feat(mail): filter messages by tags (labels)

Fixes #3323
Fixes #3835
Fixes #5338
This commit is contained in:
Francis Lachapelle
2021-10-21 17:33:39 -04:00
parent 175e3802b7
commit 800e21b05d
5 changed files with 79 additions and 9 deletions
@@ -400,6 +400,12 @@
if (this.$flaggedOnly)
options.flaggedOnly = 1;
var labels = _.filter(_.keys(this.$filteredLabels), function (k) {
return !!_this.$filteredLabels[k];
});
if (labels.length)
options.labels = labels;
// Restart the refresh timer, if needed
if (!Mailbox.$virtualMode) {
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
@@ -675,6 +681,29 @@
});
};
/**
* @function getLabels
* @memberof Mailbox.prototype
* @desc Fetch the list of labels associated to the mailbox. Use the cached value if available.
* @returns a promise of the HTTP operation
*/
Mailbox.prototype.getLabels = function() {
var _this = this;
if (this.$labels)
return this.$labels;
this.$filteredLabels = {};
return Mailbox.$$resource.fetch(this.id, 'labels').then(function(data) {
_this.$labels = data;
return _this.$labels;
});
};
Mailbox.prototype.filteredByLabel = function() {
return _.includes(this.$filteredLabels, 1);
};
/**
* @function $flagMessages
* @memberof Mailbox.prototype
@@ -32,6 +32,9 @@
this.messageDialog = null; // also access from Message controller
this.mode = { search: false, multiple: 0 };
if (!Mailbox.$virtualMode)
this.selectedFolder.getLabels(); // fetch labels from server
_registerHotkeys(hotkeys);
// Expunge mailbox when leaving the Mail module