summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-08-29 13:56:53 +0200
committerAlexandre Kühn <aku@odoo.com>2018-08-30 13:26:07 +0200
commitbe44efe852e96840ff6db139ea66952cbad74e1a (patch)
treef94923504aa3b7982c7867d7c170ab54fb8df474 /addons/mail/static/src/js/models
parentbd43df539ff08c3caa4799226922633a928e37a2 (diff)
[REF] mail: clean some JS code
1. Removed `getLocalMessages` method in mailbox, and replaced with an override on `getMessages`. (This method was used before the distinction was made between `getMessages` and `fetchMessages`) 2. Removed unused method `_warnUpdatedUnreadCounter` in abstract thread window. (Leftover from an early POC) 3. Set the default value `''` for the status of a thread. (The method `getStatus` should always return a string) 4. Enforce default value `false` for detached status of channel. (The method `isDetached` should always return a boolean) 5. Improve readability of some tests. (removed useless variables and/or redundant code)
Diffstat (limited to 'addons/mail/static/src/js/models')
-rw-r--r--addons/mail/static/src/js/models/threads/abstract_thread.js4
-rw-r--r--addons/mail/static/src/js/models/threads/channel.js3
-rw-r--r--addons/mail/static/src/js/models/threads/mailbox.js19
3 files changed, 11 insertions, 15 deletions
diff --git a/addons/mail/static/src/js/models/threads/abstract_thread.js b/addons/mail/static/src/js/models/threads/abstract_thread.js
index 322541af016..b0a7f1d0b2e 100644
--- a/addons/mail/static/src/js/models/threads/abstract_thread.js
+++ b/addons/mail/static/src/js/models/threads/abstract_thread.js
@@ -16,7 +16,7 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
* @param {Object} params.data
* @param {integer|string} params.data.id the ID of this thread
* @param {string} params.data.name the name of this thread
- * @param {string} params.data.status the status of this thread
+ * @param {string} [params.data.status=''] the status of this thread
* @param {Object} params.parent Object with the event-dispatcher mixin
* (@see {web.mixins.EventDispatcherMixin})
*/
@@ -27,7 +27,7 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
this._folded = false; // threads are unfolded by default
this._id = params.data.id;
this._name = params.data.name;
- this._status = params.data.status;
+ this._status = params.data.status || '';
this._unreadCounter = 0; // amount of messages not yet been read
},
diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js
index 8f0f664b6b0..51ebe34a651 100644
--- a/addons/mail/static/src/js/models/threads/channel.js
+++ b/addons/mail/static/src/js/models/threads/channel.js
@@ -51,7 +51,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, {
this._autoswitch = 'autoswitch' in options ? options.autoswitch : true;
this._commands = undefined;
this._creatorUID = data.create_uid;
- this._detached = data.is_minimized;
+ this._detached = data.is_minimized || false;
this._directPartnerID = undefined;
this._folded = data.state === 'folded';
// if set: hide 'Leave channel' button
@@ -66,7 +66,6 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, {
// number of messages in this channel that are in inbox.
this._needactionCounter = data.message_needaction_counter || 0;
this._serverType = data.channel_type;
- this._status = undefined;
this._throttleFetchSeen = _.throttle(this._fetchSeen.bind(this), 3000);
// unique identifier for this channel, which is required for some rpc
this._uuid = data.uuid;
diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js
index f3e0754ee20..f3b541d07a7 100644
--- a/addons/mail/static/src/js/models/threads/mailbox.js
+++ b/addons/mail/static/src/js/models/threads/mailbox.js
@@ -46,11 +46,8 @@ var Mailbox = SearchableThread.extend({
this._mailboxCounter = Math.max(this._mailboxCounter - num, 0);
},
/**
- * Get the local messages of the mailbox (by local messages, we mean
- * messages that have already been fetched from the server).
- *
- * It is possible to filter on local messages that are specific to a
- * document with the `options` parameter.
+ * Override so that there are options to filter messages based on document
+ * model and ID.
*
* @param {Object} [options]
* @param {string} [options.documentModel] model of the document that the
@@ -58,15 +55,15 @@ var Mailbox = SearchableThread.extend({
* @param {integer} [options.documentID] ID of the document that the local
* messages of inbox must be linked to.
*/
- getLocalMessages: function (options) {
- var localMessages = this._cache['[]'].messages;
+ getMessages: function (options) {
+ var messages = this._super.apply(this, arguments);
if (!options) {
- return localMessages;
+ return messages;
}
if (options.documentModel && options.documentID) {
- return _.filter(localMessages, function (localMessage) {
- return localMessage.getDocumentModel() === options.documentModel &&
- localMessage.getDocumentID() === options.documentID;
+ return _.filter(messages, function (message) {
+ return message.getDocumentModel() === options.documentModel &&
+ message.getDocumentID() === options.documentID;
});
}
},