Skip to content

Commit

Permalink
fix(mail(js)): update list of labels when adding one to a message
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Oct 22, 2021
1 parent fbb7672 commit 37d06c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion UI/Templates/MailerUI/UIxMailFolderTemplate.wox
Expand Up @@ -94,7 +94,7 @@
sg-false-value="0"> <var:string label:value="Show flagged messages only"/></sg-checkmark>
</md-menu-item>
<md-menu-divider> <!-- divider --></md-menu-divider>
<md-menu-item ng-repeat="label in ::mailbox.selectedFolder.$labels track by label.imapName">
<md-menu-item ng-repeat="label in mailbox.selectedFolder.$labels track by label.imapName">
<sg-checkmark
ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
ng-model="mailbox.selectedFolder.$filteredLabels[label.imapName]"
Expand Down
9 changes: 5 additions & 4 deletions UI/WebServerResources/js/Mailer/Mailbox.service.js
Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion UI/WebServerResources/js/Mailer/Message.service.js
Expand Up @@ -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});
});
});
};

/**
Expand Down

0 comments on commit 37d06c6

Please sign in to comment.