fix(mail(js)): update list of labels when adding one to a message

This commit is contained in:
Francis Lachapelle
2021-10-22 15:20:49 -04:00
parent fbb76722e3
commit 37d06c6f21
3 changed files with 18 additions and 6 deletions
@@ -706,13 +706,14 @@
* @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() {
Mailbox.prototype.getLabels = function(options) {
var _this = this;
if (this.$labels)
return this.$labels;
if (this.$labels && !(options && options.reload))
return Mailbox.$q.when(this.$labels);
this.$filteredLabels = {};
if (angular.isUndefined(this.$filteredLabels))
this.$filteredLabels = {};
return Mailbox.$$resource.fetch(this.id, 'labels').then(function(data) {
_this.$labels = data;
return _this.$labels;
@@ -496,7 +496,18 @@
* @returns a promise of the HTTP operation
*/
Message.prototype.addTag = function(tag) {
return this.$addOrRemoveTag('add', tag);
var _this = this,
_tag = tag.replace(/^_\$/, '$');
return this.$mailbox.getLabels().then(function(labels) {
var reload = !_.find(labels, function(label) {
return label.imapName == _tag;
});
return _this.$addOrRemoveTag('add', tag).then(function() {
if (reload)
// Update the list of labels for the mailbox
_this.$mailbox.getLabels({reload: true});
});
});
};
/**