summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-09-22 16:25:24 +0000
committerSébastien Theys <seb@odoo.com>2020-09-23 09:52:30 +0000
commitf6e67650e8cb1f8f0be9e90dbaccf45692816c3e (patch)
tree1e08313ef69bfe827c321161e05ac44e27c8ca8b /addons/mail/static/src/models
parentbc00059bcd1c6475b00503e9242edd6547dbd93d (diff)
[FIX] mail: ignore `undefined` in JS fields create/write
Passing a field containing `undefined` should lead to the same result as not passing the field. Fields that relied on `undefined` as a value have been changed to use the newly introduced `clear` command, that resets a field to its default value (often that is equal to `undefined`). task-2336491 closes odoo/odoo#58308 X-original-commit: b18824485483564d2ab80f41914a3548aa528ae0 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/activity/activity.js3
-rw-r--r--addons/mail/static/src/models/attachment/attachment.js25
-rw-r--r--addons/mail/static/src/models/chat_window/chat_window.js25
-rw-r--r--addons/mail/static/src/models/discuss/discuss.js3
-rw-r--r--addons/mail/static/src/models/message/message.js2
-rw-r--r--addons/mail/static/src/models/thread/thread.js5
-rw-r--r--addons/mail/static/src/models/thread_view/thread_view.js10
7 files changed, 36 insertions, 37 deletions
diff --git a/addons/mail/static/src/models/activity/activity.js b/addons/mail/static/src/models/activity/activity.js
index 1e17185fdf2..4e654e3c456 100644
--- a/addons/mail/static/src/models/activity/activity.js
+++ b/addons/mail/static/src/models/activity/activity.js
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/models/activity/activity/js', function (require) {
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2many, many2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
function factory(dependencies) {
@@ -245,7 +246,7 @@ function factory(dependencies) {
*/
_computeNote() {
if (this.note === '<p><br></p>') {
- return undefined;
+ return clear();
}
return this.note;
}
diff --git a/addons/mail/static/src/models/attachment/attachment.js b/addons/mail/static/src/models/attachment/attachment.js
index 77ebf667db0..7399dee7b33 100644
--- a/addons/mail/static/src/models/attachment/attachment.js
+++ b/addons/mail/static/src/models/attachment/attachment.js
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/models/attachment/attachment.js', function (require
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2many, many2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
function factory(dependencies) {
@@ -142,7 +143,7 @@ function factory(dependencies) {
/**
* @private
- * @returns {string}
+ * @returns {string|undefined}
*/
_computeDefaultSource() {
if (this.fileType === 'image') {
@@ -169,15 +170,19 @@ function factory(dependencies) {
if (this.fileType === 'video') {
return `/web/image/${this.id}?model=ir.attachment`;
}
- return undefined;
+ return clear();
}
/**
* @private
- * @returns {string}
+ * @returns {string|undefined}
*/
_computeDisplayName() {
- return this.name || this.filename;
+ const displayName = this.name || this.filename;
+ if (displayName) {
+ return displayName;
+ }
+ return clear();
}
/**
@@ -185,7 +190,11 @@ function factory(dependencies) {
* @returns {string|undefined}
*/
_computeExtension() {
- return this.filename && this.filename.split('.').pop();
+ const extension = this.filename && this.filename.split('.').pop();
+ if (extension) {
+ return extension;
+ }
+ return clear();
}
/**
@@ -194,15 +203,15 @@ function factory(dependencies) {
*/
_computeFileType() {
if (this.type === 'url' && !this.url) {
- return undefined;
+ return clear();
} else if (!this.mimetype) {
- return undefined;
+ return clear();
}
const match = this.type === 'url'
? this.url.match('(youtu|.png|.jpg|.gif)')
: this.mimetype.match('(image|video|application/pdf|text)');
if (!match) {
- return undefined;
+ return clear();
}
if (match[1].match('(.png|.jpg|.gif)')) {
return 'image';
diff --git a/addons/mail/static/src/models/chat_window/chat_window.js b/addons/mail/static/src/models/chat_window/chat_window.js
index 5efcaf3b6fe..a197481037c 100644
--- a/addons/mail/static/src/models/chat_window/chat_window.js
+++ b/addons/mail/static/src/models/chat_window/chat_window.js
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/models/chat_window/chat_window.js', function (requi
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
function factory(dependencies) {
@@ -193,14 +194,6 @@ function factory(dependencies) {
* @returns {boolean}
*/
_computeIsVisible() {
- return this.manager.allOrderedVisible.includes(this);
- }
-
- /**
- * @private
- * @returns {boolean}
- */
- _computeIsVisible() {
if (!this.manager) {
return false;
}
@@ -224,12 +217,12 @@ function factory(dependencies) {
*/
_computeVisibleIndex() {
if (!this.manager) {
- return undefined;
+ return clear();
}
const visible = this.manager.visual.visible;
const index = visible.findIndex(visible => visible.chatWindowLocalId === this.localId);
if (index === -1) {
- return undefined;
+ return clear();
}
return index;
}
@@ -383,17 +376,7 @@ function factory(dependencies) {
default: false,
}),
/**
- * States whether `this` is visible or not.
- */
- isVisible: attr({
- compute: '_computeIsVisible',
- dependencies: [
- 'managerAllOrderedVisible',
- ],
- default: false,
- }),
- /**
- * Whether this chat window is visible or not. Should be considered
+ * States whether `this` is visible or not. Should be considered
* read-only. Setting this value manually will not make it visible.
* @see `makeVisible`
*/
diff --git a/addons/mail/static/src/models/discuss/discuss.js b/addons/mail/static/src/models/discuss/discuss.js
index 221d276ecd1..b05a08eea61 100644
--- a/addons/mail/static/src/models/discuss/discuss.js
+++ b/addons/mail/static/src/models/discuss/discuss.js
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/models/discuss.discuss.js', function (require) {
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
function factory(dependencies) {
@@ -235,7 +236,7 @@ function factory(dependencies) {
*/
_computeActiveId() {
if (!this.thread) {
- return undefined;
+ return clear();
}
return this.threadToActiveId(this.thread);
}
diff --git a/addons/mail/static/src/models/message/message.js b/addons/mail/static/src/models/message/message.js
index 2c3e3b53c91..f375294666c 100644
--- a/addons/mail/static/src/models/message/message.js
+++ b/addons/mail/static/src/models/message/message.js
@@ -387,7 +387,7 @@ function factory(dependencies) {
* @returns {boolean}
*/
_computeIsCurrentPartnerAuthor() {
- return (
+ return !!(
this.author &&
this.messagingCurrentPartner &&
this.messagingCurrentPartner === this.author
diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js
index 5304130345e..a1818376233 100644
--- a/addons/mail/static/src/models/thread/thread.js
+++ b/addons/mail/static/src/models/thread/thread.js
@@ -3,6 +3,7 @@ odoo.define('mail/static/src/models/thread/thread.js', function (require) {
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2many, many2one, one2many, one2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
const throttle = require('mail/static/src/utils/throttle/throttle.js');
const Timer = require('mail/static/src/utils/timer/timer.js');
const mailUtils = require('mail.utils');
@@ -1235,7 +1236,7 @@ function factory(dependencies) {
if (
this.serverFoldState === this.pendingFoldState
) {
- this.update({ pendingFoldState: undefined });
+ this.update({ pendingFoldState: clear() });
}
if (
this.isPendingPinned !== undefined &&
@@ -1246,7 +1247,7 @@ function factory(dependencies) {
if (
this.isServerPinned === this.isPendingPinned
) {
- this.update({ isPendingPinned: undefined });
+ this.update({ isPendingPinned: clear() });
}
// TODO FIXME prevent to open/close a channel on mobile when you
diff --git a/addons/mail/static/src/models/thread_view/thread_view.js b/addons/mail/static/src/models/thread_view/thread_view.js
index 599a99cc936..f2c64dabe2c 100644
--- a/addons/mail/static/src/models/thread_view/thread_view.js
+++ b/addons/mail/static/src/models/thread_view/thread_view.js
@@ -4,6 +4,7 @@ odoo.define('mail/static/src/models/thread_view/thread_view.js', function (requi
const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { RecordDeletedError } = require('mail/static/src/model/model_errors.js');
const { attr, many2many, many2one, one2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
function factory(dependencies) {
@@ -77,9 +78,13 @@ function factory(dependencies) {
*/
_computeThreadCacheInitialScrollPosition() {
if (!this.threadCache) {
- return;
+ return clear();
+ }
+ const threadCacheInitialScrollPosition = this.threadCacheInitialScrollPositions[this.threadCache.localId];
+ if (threadCacheInitialScrollPosition !== undefined) {
+ return threadCacheInitialScrollPosition;
}
- return this.threadCacheInitialScrollPositions[this.threadCache.localId];
+ return clear();
}
/**
@@ -102,7 +107,6 @@ function factory(dependencies) {
}
});
}
- return true;
}
/**