summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models/thread/thread.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-11-25 10:29:17 +0000
committerSébastien Theys <seb@odoo.com>2020-11-25 10:29:17 +0000
commit26a76f81590ae92f5bec51be1441d6779b1afe85 (patch)
tree200d0305f02ddd3ed451d78434b169f585a1be21 /addons/mail/static/src/models/thread/thread.js
parent8ad230ad64557798df09e28677f05a9f41773ead (diff)
[FIX] mail: remove illegitimate followers from chats
task-2392114 closes odoo/odoo#62309 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models/thread/thread.js')
-rw-r--r--addons/mail/static/src/models/thread/thread.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js
index 389b5aa3580..bb23735c62e 100644
--- a/addons/mail/static/src/models/thread/thread.js
+++ b/addons/mail/static/src/models/thread/thread.js
@@ -819,6 +819,7 @@ function factory(dependencies) {
res_model: this.model,
},
}, { shadow: true }));
+ this.update({ areFollowersLoaded: true });
if (followers.length > 0) {
this.update({
followers: [['insert-and-replace', followers.map(data =>
@@ -1427,6 +1428,25 @@ function factory(dependencies) {
}
/**
+ * Cleans followers of current thread. In particular, chats are supposed
+ * to work with "members", not with "followers". This clean up is only
+ * necessary to remove illegitimate followers in stable version, it can
+ * be removed in master after proper migration to clean the database.
+ *
+ * @private
+ */
+ _onChangeFollowersPartner() {
+ if (this.channel_type !== 'chat') {
+ return;
+ }
+ for (const follower of this.followers) {
+ if (follower.partner) {
+ follower.remove();
+ }
+ }
+ }
+
+ /**
* @private
*/
_onChangeLastSeenByCurrentPartnerMessageId() {
@@ -1436,6 +1456,26 @@ function factory(dependencies) {
}
/**
+ * Fetches followers of chats when they are displayed for the first
+ * time. This is necessary to clean the followers.
+ * @see `_onChangeFollowersPartner` for more information.
+ *
+ * @private
+ */
+ _onChangeThreadViews() {
+ if (this.channel_type !== 'chat') {
+ return;
+ }
+ if (this.threadViews.length === 0) {
+ return;
+ }
+ if (this.areFollowersLoaded) {
+ return;
+ }
+ this.refreshFollowers();
+ }
+
+ /**
* Handles change of pinned state coming from the server. Useful to
* clear pending state once server acknowledged the change.
*
@@ -1565,6 +1605,13 @@ function factory(dependencies) {
areAttachmentsLoaded: attr({
default: false,
}),
+ /**
+ * States whether followers have been loaded at least once for this
+ * thread.
+ */
+ areFollowersLoaded: attr({
+ default: false,
+ }),
attachments: many2many('mail.attachment', {
inverse: 'threads',
}),
@@ -1854,6 +1901,16 @@ function factory(dependencies) {
dependencies: ['messages'],
}),
/**
+ * Not a real field, used to trigger `_onChangeFollowersPartner` when one of
+ * the dependencies changes.
+ */
+ onChangeFollowersPartner: attr({
+ compute: '_onChangeFollowersPartner',
+ dependencies: [
+ 'followersPartner',
+ ],
+ }),
+ /**
* Not a real field, used to trigger `_onChangeLastSeenByCurrentPartnerMessageId` when one of
* the dependencies changes.
*/
@@ -1864,6 +1921,16 @@ function factory(dependencies) {
],
}),
/**
+ * Not a real field, used to trigger `_onChangeThreadViews` when one of
+ * the dependencies changes.
+ */
+ onChangeThreadView: attr({
+ compute: '_onChangeThreadViews',
+ dependencies: [
+ 'threadViews',
+ ],
+ }),
+ /**
* Not a real field, used to trigger `_onIsServerPinnedChanged` when one of
* the dependencies changes.
*/