summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-08-05 14:03:05 +0000
committerSébastien Theys <seb@odoo.com>2020-08-05 15:09:34 +0000
commit9216bdcb6f0bbb20900a33bbf7283e6e4fda1b2c (patch)
treece2c02403afc038f552436997fb3ba9f3ab1c1ac /addons/mail/static/src/models
parent9432d547053605a0807e82499123c0deede23d6b (diff)
[FIX] mail: clean up JS relations by storing records
Remove the support and the conversion from record to localId and back from localId to record. Part of task-2308312 closes odoo/odoo#55481 X-original-commit: fc5e8be4e65518770a281f0dffae07854d20073a Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
-rw-r--r--addons/mail/static/src/models/attachment/attachment.js2
-rw-r--r--addons/mail/static/src/models/chat_window_manager/chat_window_manager.js6
-rw-r--r--addons/mail/static/src/models/chatter/chatter.js22
-rw-r--r--addons/mail/static/src/models/dialog/dialog.js22
-rw-r--r--addons/mail/static/src/models/dialog_manager/dialog_manager.js59
-rw-r--r--addons/mail/static/src/models/discuss/discuss.js2
-rw-r--r--addons/mail/static/src/models/follower/follower.js2
-rw-r--r--addons/mail/static/src/models/message_seen_indicator/message_seen_indicator.js4
-rw-r--r--addons/mail/static/src/models/messaging/messaging.js18
-rw-r--r--addons/mail/static/src/models/model/model.js6
-rw-r--r--addons/mail/static/src/models/thread/thread.js18
-rw-r--r--addons/mail/static/src/models/thread_cache/thread_cache.js8
-rw-r--r--addons/mail/static/src/models/thread_viewer/thread_viewer.js4
13 files changed, 64 insertions, 109 deletions
diff --git a/addons/mail/static/src/models/attachment/attachment.js b/addons/mail/static/src/models/attachment/attachment.js
index d4dcfb20fac..a9adce2579f 100644
--- a/addons/mail/static/src/models/attachment/attachment.js
+++ b/addons/mail/static/src/models/attachment/attachment.js
@@ -87,7 +87,7 @@ function factory(dependencies) {
return;
}
this.env.messaging.dialogManager.open('mail.attachment_viewer', {
- attachment: [['replace', attachment]],
+ attachment: [['link', attachment]],
attachments: [['replace', attachments]],
});
}
diff --git a/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js b/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js
index 3b054f83a30..5070508b621 100644
--- a/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js
+++ b/addons/mail/static/src/models/chat_window_manager/chat_window_manager.js
@@ -254,9 +254,9 @@ function factory(dependencies) {
_computeLastVisible() {
const { length: l, [l - 1]: lastVisible } = this.allOrderedVisible;
if (!lastVisible) {
- return [['unlink-all']];
+ return [['unlink']];
}
- return [['replace', lastVisible]];
+ return [['link', lastVisible]];
}
/**
@@ -268,7 +268,7 @@ function factory(dependencies) {
if (!chatWindow) {
return [['unlink']];
}
- return [['replace', chatWindow]];
+ return [['link', chatWindow]];
}
/**
diff --git a/addons/mail/static/src/models/chatter/chatter.js b/addons/mail/static/src/models/chatter/chatter.js
index 4df875a0898..61757004a91 100644
--- a/addons/mail/static/src/models/chatter/chatter.js
+++ b/addons/mail/static/src/models/chatter/chatter.js
@@ -50,6 +50,10 @@ function factory(dependencies) {
}
async refreshActivities() {
+ if (!this.thread || this.thread.isTemporary) {
+ this.update({ activities: [['unlink-all']] });
+ return;
+ }
// A bit "extreme", may be improved
const [{ activity_ids: newActivityIds }] = await this.async(() => this.env.services.rpc({
model: this.thread.model,
@@ -166,18 +170,24 @@ function factory(dependencies) {
}
}
- if (previous.activityIds.join(',') !== this.activityIds.join(',')) {
+ if (
+ !previous.activityIds ||
+ previous.activityIds.join(',') !== this.activityIds.join(',')
+ ) {
this.refreshActivities();
}
if (
- previous.followerIds.join(',') !== this.followerIds.join(',') &&
- !this.thread.isTemporary
+ !previous.followerIds ||
+ previous.followerIds.join(',') !== this.followerIds.join(',')
) {
- this.thread.refreshFollowers();
+ if (this.thread) {
+ this.thread.refreshFollowers();
+ }
}
if (
+ !previous.messageIds ||
previous.thread !== this.thread ||
- (this.thread && this.messageIds.join(',') !== previous.messageIds.join(','))
+ this.messageIds.join(',') !== previous.messageIds.join(',')
) {
this.refresh();
}
@@ -316,7 +326,7 @@ function factory(dependencies) {
threadId: attr(),
threadModel: attr(),
threadViewer: one2one('mail.thread_viewer', {
- autocreate: true,
+ default: [['create']],
}),
todayActivities: one2many('mail.activity', {
compute: '_computeTodayActivities',
diff --git a/addons/mail/static/src/models/dialog/dialog.js b/addons/mail/static/src/models/dialog/dialog.js
index d4b0bcddfb5..018951fe092 100644
--- a/addons/mail/static/src/models/dialog/dialog.js
+++ b/addons/mail/static/src/models/dialog/dialog.js
@@ -6,27 +6,7 @@ const { many2one, one2one } = require('mail/static/src/model/model_field.js');
function factory(dependencies) {
- class Dialog extends dependencies['mail.model'] {
-
- /**
- * @override
- */
- delete() {
- if (this.manager) {
- this.manager.unregister(this);
- }
- super.delete();
- }
-
- //----------------------------------------------------------------------
- // Public
- //----------------------------------------------------------------------
-
- close() {
- this.delete();
- }
-
- }
+ class Dialog extends dependencies['mail.model'] {}
Dialog.fields = {
manager: many2one('mail.dialog_manager', {
diff --git a/addons/mail/static/src/models/dialog_manager/dialog_manager.js b/addons/mail/static/src/models/dialog_manager/dialog_manager.js
index 024172f7cdf..4d86e340cee 100644
--- a/addons/mail/static/src/models/dialog_manager/dialog_manager.js
+++ b/addons/mail/static/src/models/dialog_manager/dialog_manager.js
@@ -2,7 +2,7 @@ odoo.define('mail/static/src/models/dialog_manager/dialog_manager.js', function
'use strict';
const { registerNewModel } = require('mail/static/src/model/model_core.js');
-const { attr, one2many } = require('mail/static/src/model/model_field.js');
+const { one2many } = require('mail/static/src/model/model_field.js');
function factory(dependencies) {
@@ -13,21 +13,10 @@ function factory(dependencies) {
//----------------------------------------------------------------------
/**
- * @param {mail.dialog} dialog
- */
- close(dialog) {
- this.unregister(dialog);
- dialog.delete();
- }
-
- /**
* @param {string} modelName
* @param {Object} [recordData]
*/
open(modelName, recordData) {
- const dialog = this.env.models['mail.dialog'].create({
- manager: [['link', this]],
- });
if (!modelName) {
throw new Error("Dialog should have a link to a model");
}
@@ -36,53 +25,17 @@ function factory(dependencies) {
throw new Error(`No model exists with name ${modelName}`);
}
const record = Model.create(recordData);
- dialog.update({ record: [['link', record]] });
- this.update({ _ordered: this._ordered.concat([dialog.localId]) });
- return dialog;
- }
-
- /**
- * @param {mail.dialog} dialog
- */
- unregister(dialog) {
- if (!this.allOrdered.includes(dialog)) {
- return;
- }
- this.update({
- _ordered: this._ordered.filter(
- dialogLocalId => dialogLocalId !== dialog.localId
- ),
- dialogs: [['unlink', dialog]],
+ const dialog = this.env.models['mail.dialog'].create({
+ manager: [['link', this]],
+ record: [['link', record]],
});
+ return dialog;
}
- //----------------------------------------------------------------------
- // Private
- //----------------------------------------------------------------------
-
- /**
- * FIXME: dependent on implementation that uses arbitrary order in relations!!
- *
- * @private
- * @returns {mail.dialog}
- */
- _computeAllOrdered() {
- return [['replace', this._ordered.map(dialogLocalId =>
- this.env.models['mail.dialog'].get(dialogLocalId)
- )]];
- }
}
DialogManager.fields = {
- _ordered: attr({ default: [] }),
- // FIXME: dependent on implementation that uses arbitrary order in relations!!
- allOrdered: one2many('mail.dialog', {
- compute: '_computeAllOrdered',
- dependencies: [
- '_ordered',
- 'dialogs',
- ],
- }),
+ // FIXME: dependent on implementation that uses insert order in relations!!
dialogs: one2many('mail.dialog', {
inverse: 'manager',
isCausal: true,
diff --git a/addons/mail/static/src/models/discuss/discuss.js b/addons/mail/static/src/models/discuss/discuss.js
index 7b4961c87be..b111c8726f8 100644
--- a/addons/mail/static/src/models/discuss/discuss.js
+++ b/addons/mail/static/src/models/discuss/discuss.js
@@ -462,7 +462,7 @@ function factory(dependencies) {
related: 'thread.model',
}),
threadViewer: one2one('mail.thread_viewer', {
- autocreate: true,
+ default: [['create']],
isCausal: true,
}),
};
diff --git a/addons/mail/static/src/models/follower/follower.js b/addons/mail/static/src/models/follower/follower.js
index 42e7216392e..4c44b788d4d 100644
--- a/addons/mail/static/src/models/follower/follower.js
+++ b/addons/mail/static/src/models/follower/follower.js
@@ -111,7 +111,7 @@ function factory(dependencies) {
}
}
this._subtypesListDialog = this.env.messaging.dialogManager.open('mail.follower_subtype_list', {
- follower: [['replace', this]],
+ follower: [['link', this]],
});
}
diff --git a/addons/mail/static/src/models/message_seen_indicator/message_seen_indicator.js b/addons/mail/static/src/models/message_seen_indicator/message_seen_indicator.js
index 19b4706ba1f..78f7431214f 100644
--- a/addons/mail/static/src/models/message_seen_indicator/message_seen_indicator.js
+++ b/addons/mail/static/src/models/message_seen_indicator/message_seen_indicator.js
@@ -20,8 +20,8 @@ function factory(dependencies) {
*/
static computeId(message, thread) {
if (message && thread) {
- const messageId = Number.isInteger(message) ? message : message.id;
- const threadId = Number.isInteger(thread) ? thread : thread.id;
+ const messageId = typeof message !== 'object' ? message : message.id;
+ const threadId = typeof thread !== 'object' ? thread : thread.id;
return [messageId, threadId].join('-');
}
return undefined;
diff --git a/addons/mail/static/src/models/messaging/messaging.js b/addons/mail/static/src/models/messaging/messaging.js
index b58de718cde..a4e5d27eced 100644
--- a/addons/mail/static/src/models/messaging/messaging.js
+++ b/addons/mail/static/src/models/messaging/messaging.js
@@ -132,7 +132,7 @@ function factory(dependencies) {
default: {},
}),
chatWindowManager: one2one('mail.chat_window_manager', {
- autocreate: true,
+ default: [['create']],
inverse: 'messaging',
isCausal: true,
}),
@@ -142,15 +142,15 @@ function factory(dependencies) {
currentPartner: one2one('mail.partner'),
currentUser: one2one('mail.user'),
device: one2one('mail.device', {
- autocreate: true,
+ default: [['create']],
isCausal: true,
}),
dialogManager: one2one('mail.dialog_manager', {
- autocreate: true,
+ default: [['create']],
isCausal: true,
}),
discuss: one2one('mail.discuss', {
- autocreate: true,
+ default: [['create']],
inverse: 'messaging',
isCausal: true,
}),
@@ -163,7 +163,7 @@ function factory(dependencies) {
*/
inbox: one2one('mail.thread'),
initializer: one2one('mail.messaging_initializer', {
- autocreate: true,
+ default: [['create']],
inverse: 'messaging',
isCausal: true,
}),
@@ -171,11 +171,11 @@ function factory(dependencies) {
default: false,
}),
locale: one2one('mail.locale', {
- autocreate: true,
+ default: [['create']],
isCausal: true,
}),
messagingMenu: one2one('mail.messaging_menu', {
- autocreate: true,
+ default: [['create']],
inverse: 'messaging',
isCausal: true,
}),
@@ -184,11 +184,11 @@ function factory(dependencies) {
*/
moderation: one2one('mail.thread'),
notificationGroupManager: one2one('mail.notification_group_manager', {
- autocreate: true,
+ default: [['create']],
isCausal: true,
}),
notificationHandler: one2one('mail.messaging_notification_handler', {
- autocreate: true,
+ default: [['create']],
inverse: 'messaging',
isCausal: true,
}),
diff --git a/addons/mail/static/src/models/model/model.js b/addons/mail/static/src/models/model/model.js
index c7e4e4f2641..be02afeeaee 100644
--- a/addons/mail/static/src/models/model/model.js
+++ b/addons/mail/static/src/models/model/model.js
@@ -89,10 +89,12 @@ function factory() {
*
* @static
* @param {string} localId
+ * @param {Object} param1
+ * @param {boolean} [param1.isCheckingInheritance]
* @returns {mail.model|undefined}
*/
- static get(localId) {
- return this.env.modelManager.get(this, localId);
+ static get(localId, { isCheckingInheritance } = {}) {
+ return this.env.modelManager.get(this, localId, { isCheckingInheritance });
}
/**
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js
index 4459912d6f6..6b6f9a4c1d4 100644
--- a/addons/mail/static/src/models/thread/thread.js
+++ b/addons/mail/static/src/models/thread/thread.js
@@ -542,7 +542,7 @@ function factory(dependencies) {
openExpanded() {
const discuss = this.env.messaging.discuss;
if (['mail.channel', 'mail.box'].includes(this.model)) {
- discuss.threadViewer.update({ thread: [['replace', this]] });
+ discuss.threadViewer.update({ thread: [['link', this]] });
this.env.bus.trigger('do-action', {
action: 'mail.action_discuss',
options: {
@@ -581,6 +581,10 @@ function factory(dependencies) {
* Refresh followers information from server.
*/
async refreshFollowers() {
+ if (this.isTemporary) {
+ this.update({ followers: [['unlink-all']] });
+ return;
+ }
// FIXME Do that with only one RPC (see task-2243180)
const [{ message_follower_ids: followerIds }] = await this.async(() => this.env.services.rpc({
model: this.model,
@@ -895,7 +899,7 @@ function factory(dependencies) {
) {
return [['unlink-all']];
}
- return [['replace', currentPartnerOrderedSeenMessages.slice().pop()]];
+ return [['link', currentPartnerOrderedSeenMessages.slice().pop()]];
}
/**
@@ -907,7 +911,10 @@ function factory(dependencies) {
length: l,
[l - 1]: lastMessage,
} = this.orderedMessages;
- return [['replace', lastMessage]];
+ if (lastMessage) {
+ return [['link', lastMessage]];
+ }
+ return [['unlink']];
}
/**
@@ -922,7 +929,10 @@ function factory(dependencies) {
length: l,
[l - 1]: lastNeedactionMessage,
} = orderedNeedactionMessages;
- return [['replace', lastNeedactionMessage]];
+ if (lastNeedactionMessage) {
+ return [['link', lastNeedactionMessage]];
+ }
+ return [['unlink']];
}
/**
diff --git a/addons/mail/static/src/models/thread_cache/thread_cache.js b/addons/mail/static/src/models/thread_cache/thread_cache.js
index 9d0b4e98e57..0c2ef2af35f 100644
--- a/addons/mail/static/src/models/thread_cache/thread_cache.js
+++ b/addons/mail/static/src/models/thread_cache/thread_cache.js
@@ -142,9 +142,9 @@ function factory(dependencies) {
[l - 1]: lastFetchedMessage,
} = this.orderedFetchedMessages;
if (!lastFetchedMessage) {
- return [['unlink-all']];
+ return [['unlink']];
}
- return [['replace', lastFetchedMessage]];
+ return [['link', lastFetchedMessage]];
}
/**
@@ -157,9 +157,9 @@ function factory(dependencies) {
[l - 1]: lastMessage,
} = this.orderedMessages;
if (!lastMessage) {
- return [['unlink-all']];
+ return [['unlink']];
}
- return [['replace', lastMessage]];
+ return [['link', lastMessage]];
}
/**
diff --git a/addons/mail/static/src/models/thread_viewer/thread_viewer.js b/addons/mail/static/src/models/thread_viewer/thread_viewer.js
index 52fadc74015..413448c6c6f 100644
--- a/addons/mail/static/src/models/thread_viewer/thread_viewer.js
+++ b/addons/mail/static/src/models/thread_viewer/thread_viewer.js
@@ -72,7 +72,7 @@ function factory(dependencies) {
*/
handleVisibleMessage(message) {
if (!this.lastVisibleMessage || this.lastVisibleMessage.id < message.id) {
- this.update({ lastVisibleMessage: [['replace', message]] });
+ this.update({ lastVisibleMessage: [['link', message]] });
}
}
@@ -102,7 +102,7 @@ function factory(dependencies) {
if (!this.thread) {
return [];
}
- return [['replace', this.thread.cache(this.stringifiedDomain)]];
+ return [['link', this.thread.cache(this.stringifiedDomain)]];
}
/**