diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:02:19 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | 1ae64793fa489b2c1d07408cd9671bc7126f78fa (patch) | |
| tree | 23d908222f4e705b908dd23ef3823c26daf3baf0 /addons/mail/static/src/js/models/threads | |
| parent | aa900d976f6fbb10f3940639b4d918d31a7556ca (diff) | |
[REF] mail: adapt code after jQuery update
Part of task 1896658
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Diffstat (limited to 'addons/mail/static/src/js/models/threads')
10 files changed, 53 insertions, 49 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 a515c4d2f8a..192d0e58c93 100644 --- a/addons/mail/static/src/js/models/threads/abstract_thread.js +++ b/addons/mail/static/src/js/models/threads/abstract_thread.js @@ -150,18 +150,18 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, { * Mark the thread as read, which resets the unread counter to 0. This is * only performed if the unread counter is not 0. * - * @returns {$.Promise} + * @returns {Promise} */ markAsRead: function () { if (this._unreadCounter > 0) { return this._markAsRead(); } - return $.when(); + return Promise.resolve(); }, /** * Post a message on this thread * - * @returns {$.Promise} resolved with the message object to be sent to the + * @returns {Promise} resolved with the message object to be sent to the * server */ postMessage: function () { @@ -200,22 +200,22 @@ var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, { * Mark the thread as read * * @private - * @returns {$.Promise} + * @returns {Promise} */ _markAsRead: function () { this.resetUnreadCounter(); - return $.when(); + return Promise.resolve(); }, /** * Post a message on this thread * * @abstract * @private - * @returns {$.Promise} resolved with the message object to be sent to the + * @returns {Promise} resolved with the message object to be sent to the * server */ _postMessage: function () { - return $.when(); + return Promise.resolve(); }, /** * Warn views (e.g. discuss app, thread window, etc.) to update visually diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js index 9f0f37264db..9e9f3ac6a39 100644 --- a/addons/mail/static/src/js/models/threads/channel.js +++ b/addons/mail/static/src/js/models/threads/channel.js @@ -70,7 +70,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { this._isMyselfModerator = data.is_moderator; this._lastMessageDate = undefined; this._members = data.members || []; - // Deferred that is resolved on fetched members of this channel. + // Promise that is resolved on fetched members of this channel. this._membersDef = undefined; // number of messages that are 'needaction', which is equivalent to the // number of messages in this channel that are in inbox. @@ -129,19 +129,21 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { * @pverride */ detach: function () { - this._super.apply(this, arguments); - this._rpc({ - model: 'mail.channel', - method: 'channel_minimize', - args: [this.getUUID(), true], - }, { - shadow: true, + var self = this; + return this._super.apply(this, arguments).then(function () { + self._rpc({ + model: 'mail.channel', + method: 'channel_minimize', + args: [self.getUUID(), true], + }, { + shadow: true, + }); }); }, /** * Force fetch members of the channel * - * @returns {$.Promise<Object[]>} resolved with list of channel listeners + * @returns {Promise<Object[]>} resolved with list of channel listeners */ forceFetchMembers: function () { this._membersDef = undefined; @@ -186,7 +188,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { /** * Get listeners of a channel * - * @returns {$.Promise<Array<Object[]>>} resolved with list of list of + * @returns {Promise<Object[]>} resolved with list of list of * channel listeners. */ getMentionPartnerSuggestions: function () { @@ -302,7 +304,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { * Unsubscribes from channel * * @abstract - * @returns {$.Promise} resolve when unsubscribed + * @returns {Promise} resolve when unsubscribed */ unsubscribe: function () {}, /** @@ -381,19 +383,19 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { * * @override * @private - * @returns {$.Promise} resolved when message has been marked as read + * @returns {Promise} resolved when message has been marked as read */ _markAsRead: function () { var superDef = this._super.apply(this, arguments); var seenDef = this._notifySeen(); - return $.when(superDef, seenDef); + return Promise.all([superDef, seenDef]); }, /** * @override {mail.model.ThreadTypingMixin} * @private * @param {Object} params * @param {boolean} params.typing - * @returns {$.Promise} + * @returns {Promise} */ _notifyMyselfTyping: function (params) { return this._rpc({ @@ -424,7 +426,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, { * @override * @private * @param {Object} data data related to the new message - * @returns {$.Promise<Object>} resolved when the message has been sent to + * @returns {Promise<Object>} resolved when the message has been sent to * the server, with the object message that has been sent to the server. */ _postMessage: function (data) { diff --git a/addons/mail/static/src/js/models/threads/document_thread.js b/addons/mail/static/src/js/models/threads/document_thread.js index 6c15b39d25e..08e441610ee 100644 --- a/addons/mail/static/src/js/models/threads/document_thread.js +++ b/addons/mail/static/src/js/models/threads/document_thread.js @@ -92,7 +92,7 @@ var DocumentThread = Thread.extend({ * @param {Object} options * @param {boolean} [options.forceFetch] if true, fetch anyway, as user * clicked on 'load more'. - * @returns {$.Promise<mail.model.Message[]>} + * @returns {Promise<mail.model.Message[]>} */ fetchMessages: function (options) { var self = this; @@ -217,14 +217,14 @@ var DocumentThread = Thread.extend({ * Get most up to date messageIDs * * @private - * @returns {$.Promise} resolved when message IDs have been fetched and set + * @returns {Promise} resolved when message IDs have been fetched and set * in the model */ _fetchMessageIDs: function () { var self = this; var resID = this.getDocumentID(); if (!resID || !this._mustFetchMessageIDs) { - return $.when(); + return Promise.resolve(); } return this._rpc({ model: this.getDocumentModel(), @@ -239,7 +239,7 @@ var DocumentThread = Thread.extend({ * @private * @param {Object} options * @param {boolean} [options.forceFetch] - * @returns {$.Promise} resolved when messages have been fetched + document + * @returns {Promise} resolved when messages have been fetched + document * thread has updated messages */ _fetchMessages: function (options) { @@ -273,7 +273,7 @@ var DocumentThread = Thread.extend({ }); }); } else { - return $.when(); + return Promise.resolve(); } }); @@ -284,7 +284,7 @@ var DocumentThread = Thread.extend({ * * @override * @private - * @returns {$.Promise} resolved when messages have been marked as read on + * @returns {Promise} resolved when messages have been marked as read on * the server. */ _markAsRead: function () { @@ -299,7 +299,7 @@ var DocumentThread = Thread.extend({ * @override * @private * @param {Object} data data related to the new message - * @return {$.Promise<Object>} resolved when the message has been sent to + * @return {Promise<Object>} resolved when the message has been sent to * the server, with the object message that has been sent to the server. */ _postMessage: function (data) { diff --git a/addons/mail/static/src/js/models/threads/livechat.js b/addons/mail/static/src/js/models/threads/livechat.js index 45cab5aef10..c3b4a5e2b4d 100644 --- a/addons/mail/static/src/js/models/threads/livechat.js +++ b/addons/mail/static/src/js/models/threads/livechat.js @@ -34,7 +34,7 @@ var Livechat = TwoUserChannel.extend({ * display of a user that is typing. * * @override - * @returns {$.Promise<Array<Object[]>>} resolved with list of list of + * @returns {Promise<Object[]>} resolved with list of list of * livechat members. */ getMentionPartnerSuggestions: function () { diff --git a/addons/mail/static/src/js/models/threads/mailbox.js b/addons/mail/static/src/js/models/threads/mailbox.js index 263072f575e..bedd6af27e1 100644 --- a/addons/mail/static/src/js/models/threads/mailbox.js +++ b/addons/mail/static/src/js/models/threads/mailbox.js @@ -59,7 +59,7 @@ var Mailbox = SearchableThread.extend({ * channel, only keep the lastest message of this document/channel in the * previews. * - * @returns {$.Promise<Object[]>} + * @returns {Promise<Object[]>} */ getMessagePreviews: function () { var self = this; @@ -119,7 +119,7 @@ var Mailbox = SearchableThread.extend({ * makes only sense for 'Inbox'. * * @param {Array} domain - * @return {$.Promise} resolved when all messages have been marked as read + * @return {Promise} resolved when all messages have been marked as read * on the server */ markAllMessagesAsRead: function (domain) { @@ -133,7 +133,7 @@ var Mailbox = SearchableThread.extend({ }, }); } - return $.when(); + return Promise.resolve(); }, //-------------------------------------------------------------------------- diff --git a/addons/mail/static/src/js/models/threads/mixins/thread_typing_mixin.js b/addons/mail/static/src/js/models/threads/mixins/thread_typing_mixin.js index f995b4e09b3..7d97538dbb9 100644 --- a/addons/mail/static/src/js/models/threads/mixins/thread_typing_mixin.js +++ b/addons/mail/static/src/js/models/threads/mixins/thread_typing_mixin.js @@ -239,11 +239,11 @@ var ThreadTypingMixin = { * @private * @param {Object} params * @param {boolean} params.typing whether we are typing something or not - * @returns {$.Promise} resolved if the server is notified, rejected + * @returns {Promise} resolved if the server is notified, rejected * otherwise */ _notifyMyselfTyping: function (params) { - return $.when(); + return Promise.resolve(); }, /** * Warn views that the list of users that are currently typing on this diff --git a/addons/mail/static/src/js/models/threads/multi_user_channel.js b/addons/mail/static/src/js/models/threads/multi_user_channel.js index bac417c361d..3dab9337502 100644 --- a/addons/mail/static/src/js/models/threads/multi_user_channel.js +++ b/addons/mail/static/src/js/models/threads/multi_user_channel.js @@ -56,7 +56,7 @@ var MultiUserChannel = Channel.extend({ * Unsubscribes from channel * * @override - * @returns {$.Promise} resolve when unsubscribed + * @returns {Promise} resolve when unsubscribed */ unsubscribe: function () { return this._rpc({ diff --git a/addons/mail/static/src/js/models/threads/searchable_thread.js b/addons/mail/static/src/js/models/threads/searchable_thread.js index 8ddff5457af..511bc6348c8 100644 --- a/addons/mail/static/src/js/models/threads/searchable_thread.js +++ b/addons/mail/static/src/js/models/threads/searchable_thread.js @@ -49,7 +49,7 @@ var SearchableThread = Thread.extend({ } var cache = this._getCache(domain); if (cache.loaded) { - return $.when(cache.messages); + return Promise.all(cache.messages); } else { return this._fetchMessages(domain); } @@ -159,7 +159,7 @@ var SearchableThread = Thread.extend({ * @private * @param {Array} [pDomain] filter on the messages of the channel * @param {boolean} [loadMore] Whether it should load more message - * @return {$.Promise<mail.model.Message[]>} resolved with list of messages + * @return {Promise<mail.model.Message[]>} resolved with list of messages */ _fetchMessages: function (pDomain, loadMore) { var self = this; diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js index 8c622779bb3..8f4e8956d27 100644 --- a/addons/mail/static/src/js/models/threads/thread.js +++ b/addons/mail/static/src/js/models/threads/thread.js @@ -58,12 +58,13 @@ var Thread = AbstractThread.extend(ServicesMixin, { * of this thread. Otherwise unfold it while detaching it. * @param {boolean} [options.passively=false] if set, if the thread window * will be created passively. + * @returns {Promise} */ detach: function (options) { options = options || {}; this._detached = true; this._folded = options.keepFoldState ? this._folded : false; - this._warnUpdatedWindowState({ + return this._warnUpdatedWindowState({ passively: options.passively, }); }, @@ -79,10 +80,10 @@ var Thread = AbstractThread.extend(ServicesMixin, { * `this.LIMIT` number of messages at a time. * * @abstract - * @returns {$.Promise<mail.model.Message[]>} + * @returns {Promise<mail.model.Message[]>} */ fetchMessages: function () { - return $.when([]); + return Promise.resolve([]); }, /** * Updates the folded state of the thread. Must be overriden to reflect @@ -110,10 +111,10 @@ var Thread = AbstractThread.extend(ServicesMixin, { * By default, a thread has not listener. * * @abstract - * @returns {$.Promise<Array<Object[]>>} + * @returns {Promise<Array<Object[]>>} */ getMentionPartnerSuggestions: function () { - return $.when([]); + return Promise.resolve([]); }, /** * Returns the information required to render the preview of this channel. @@ -287,10 +288,10 @@ var Thread = AbstractThread.extend(ServicesMixin, { /** * @abstract * @private - * @return {$.Promise} + * @return {Promise} */ _fetchMessages: function () { - return $.when(); + return Promise.resolve(); }, /** * Replace character representations of emojis by their unicode @@ -330,7 +331,7 @@ var Thread = AbstractThread.extend(ServicesMixin, { * @abstract * @private * @param {Object} data - * @returns {$.Promise<Object>} resolved with the message object to be sent + * @returns {Promise<Object>} resolved with the message object to be sent * to the server */ _postMessage: function (data) { @@ -355,7 +356,7 @@ var Thread = AbstractThread.extend(ServicesMixin, { messageData.subject = data.subject; } return this._super.apply(this, arguments).then(function () { - return $.when(messageData); + return messageData; }); }, /** @@ -374,10 +375,11 @@ var Thread = AbstractThread.extend(ServicesMixin, { * @private * @param {Object} [options={}] * @param {boolean} [options.passively=false] + * @returns {Promise} */ _warnUpdatedWindowState: function (options) { options = options || {}; - this.call('mail_service', 'updateThreadWindow', this.getID(), options); + return this.call('mail_service', 'updateThreadWindow', this.getID(), options); }, }); diff --git a/addons/mail/static/src/js/models/threads/two_user_channel.js b/addons/mail/static/src/js/models/threads/two_user_channel.js index 204fd95eb82..54a4145bd13 100644 --- a/addons/mail/static/src/js/models/threads/two_user_channel.js +++ b/addons/mail/static/src/js/models/threads/two_user_channel.js @@ -15,7 +15,7 @@ var TwoUserChannel = Channel.extend({ * Unpin from two-user thread * * @override - * @returns {$.Promise} resolve when unsubscribed + * @returns {Promise} resolve when unsubscribed */ unsubscribe: function () { return this._rpc({ |
