diff --git a/addons/mail/static/src/js/followers.js b/addons/mail/static/src/js/followers.js index 651165dde30..5859d632fea 100644 --- a/addons/mail/static/src/js/followers.js +++ b/addons/mail/static/src/js/followers.js @@ -203,7 +203,9 @@ var Followers = AbstractField.extend({ return $.when(def).then(function (results) { if (results) { self.followers = _.uniq(results.followers.concat(self.followers), 'id'); - self.subtypes = results.subtypes; + if (results.subtypes) { //read_followers will return False if current user is not in the list + self.subtypes = results.subtypes; + } } // filter out previously fetched followers that are no longer following self.followers = _.filter(self.followers, function (follower) { @@ -290,6 +292,15 @@ var Followers = AbstractField.extend({ }); } else { var kwargs = _.extend({}, ids); + if (follower_id === undefined || follower_id === this.partnerID) { + //this.subtypes will only be updated if the current user + //just added himself to the followers. We need to update + //the subtypes manually when editing subtypes + //for current user + _.each(this.subtypes, function (subtype) { + subtype.followed = checklist.indexOf(subtype.id) > -1; + }); + } kwargs.subtype_ids = checklist; kwargs.context = {}; // FIXME this._rpc({ diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index a2b6566f4d0..a8b8a3adadf 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -1449,11 +1449,6 @@ QUnit.test('followers widget: follow/unfollow, edit subtypes', function (assert) _.each(subtypes, function (subtype) { subtype.followed = _.contains(args.kwargs.subtype_ids, subtype.id); }); - // hack: the server creates a new follower each time the subtypes are updated - // so we need here to mock that weird behavior here, as the followers widget - // relies on that behavior - this.data.partner.records[0].message_follower_ids = [2]; - followers[0].id = 2; } else { // follow this.data.partner.records[0].message_follower_ids = [1]; @@ -1472,6 +1467,7 @@ QUnit.test('followers widget: follow/unfollow, edit subtypes', function (assert) return $.when({ followers: followers, subtypes: subtypes, + // caution, subtype will only be returned if current user is in args follower list }); } if (route === '/web/dataset/call_kw/partner/message_unsubscribe') {