diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-06-15 18:12:21 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-06-15 18:12:21 +0000 |
| commit | 3fea5b2136627c1d7e83b2a5e111952fe3eb10a1 (patch) | |
| tree | 5eefad07972a87ce4689b83260f981bc87aadad4 /addons/mail/static/src/js/models/threads/searchable_thread.js | |
| parent | 0a82848606151ef60eb6523e9c4c161171f214e7 (diff) | |
[REF] mail, *: refactor messaging with OWL
This commit is a significant rewriting of client-side discuss, chatter,
chat window, and messaging menu using OWL. The behavior should be broadly
the same, with some slight functional changes here and there.
From a technical standpoint, the code of messaging is mainly organized in 2
main groups of modules:
- models, which are logical entities that depict the client-side state of
messaging as a whole.
- components, which are in charge of displaying information from models.
This refactoring also introduces new JS guidelines regarding folder structure
(/static) and naming rules for JS modules.
Community PR: https://github.com/odoo/odoo/pull/39023
Enterprise PR: https://github.com/odoo/enterprise/pull/6249
Task-1914207
This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier,
with the precious help of Lucas to speed it up towards the end.
closes odoo/odoo#39023
Related: odoo/enterprise#6249
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Co-authored-by: Alexandre Kühn <aku@odoo.com>
Co-authored-by: Julien Giannone <jgi@odoo.com>
Co-authored-by: Lucas Perais <lpe@odoo.com>
Co-authored-by: Sébastien Theys <seb@odoo.com>
Co-authored-by: Xavier Dubuc <xdu@odoo.com>
Diffstat (limited to 'addons/mail/static/src/js/models/threads/searchable_thread.js')
| -rw-r--r-- | addons/mail/static/src/js/models/threads/searchable_thread.js | 244 |
1 files changed, 0 insertions, 244 deletions
diff --git a/addons/mail/static/src/js/models/threads/searchable_thread.js b/addons/mail/static/src/js/models/threads/searchable_thread.js deleted file mode 100644 index c2a48a2d410..00000000000 --- a/addons/mail/static/src/js/models/threads/searchable_thread.js +++ /dev/null @@ -1,244 +0,0 @@ -odoo.define('mail.model.SearchableThread', function (require) { -"use strict"; - -var Thread = require('mail.model.Thread'); - -var session = require('web.session'); - -/** - * This is a version of a thread that is handling a cache. - * Basically, this cache is an object indexed by stringified indexes. - * These indexes represent the domain of messages that match this domain. - * - * Any threads that are instances of this Class can be used with a search view, - * in order to make searches on messages in a thread. - */ -var SearchableThread = Thread.extend({ - - /** - * @override - * @param {Object} params - * @param {Object} params.data - * @param {integer} [params.data.seen_message_id=undefined] - */ - init: function (params) { - this._super.apply(this, arguments); - - this._cache = { - '[]': { - allHistoryLoaded: false, - loaded: false, - messages: [], - } - }; - this._lastSeenMessageID = params.data.seen_message_id; - }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * @override - * @param {Array} [domain] - * @param {boolean} [loadMore=false] - */ - fetchMessages: function (domain, loadMore) { - if (loadMore) { - return this._fetchMessages(domain, true); - } - var cache = this._getCache(domain); - if (cache.loaded) { - return Promise.all(cache.messages); - } else { - return this._fetchMessages(domain); - } - }, - /** - * Get the last seen message for a given thread - * - * @return {integer|null} last seen message ID (if any) - */ - getLastSeenMessageID: function () { - return this._lastSeenMessageID || null; - }, - /** - * @override - * @param {Object} [options={}] - * @param {Array} [options.domain=[]] - * @return {mail.model.Message[]} - */ - getMessages: function (options) { - options = options || {}; - var domain = options.domain || []; - return this._getCache(domain).messages; - }, - /** - * Override so that a thread can tell whether there are message based on - * the domain. - * - * @override - * @param {Object} [options={}] - * @param {Array} [options.domain=[]] - * @returns {boolean} - */ - hasMessages: function (options) { - options = options || {}; - var domain = options.domain || []; - return !_.isEmpty(this.getMessages({ domain: domain })); - }, - /** - * Invalidate the caches of the thread - */ - invalidateCaches: function () { - this._cache = _.pick(this._cache, '[]'); - }, - /** - * State whether all messages have been loaded or not - * - * @param {Array} domain - * @return {boolean} - */ - isAllHistoryLoaded: function (domain) { - return this._getCache(domain).allHistoryLoaded; - }, - /** - * Remove message with ID `messageID` from this thread - * - * This is equivalent to removing this message from all the caches - * - * @param {integer} messageID - */ - removeMessage: function (messageID) { - _.each(this._cache, function (cache) { - cache.messages = _.reject(cache.messages, function (message) { - return message.getID() === messageID; - }); - }); - }, - /** - * Set 'messageID' as the ID of the last message seen in this thread - * - * @param {integer} messageID - */ - setLastSeenMessageID: function (messageID) { - this._lastSeenMessageID = messageID; - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Add the message to this thread - * - * @override - * @private - * @param {mail.model.Message} message - * @param {Object} [options={}] - * @param {Array} [options.domain=[]] - * @param {boolean} [options.incrementUnread=false] - */ - _addMessage: function (message, options) { - options = options || {}; - this._super.apply(this, arguments); - var cache = this._getCache(options.domain || []); - var index = _.sortedIndex(cache.messages, message, function (msg) { - return msg.getID(); - }); - if (cache.messages[index] !== message) { - cache.messages.splice(index, 0, message); - } - if ( - !message.isMyselfAuthor() && - options.incrementUnread && - message.getType() !== 'notification' - ) { - this._incrementUnreadCounter(); - } - }, - /** - * Gets messages from thread - * - * @override - * @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 - */ - _fetchMessages: function (pDomain, loadMore) { - var self = this; - var domain = this._getThreadDomain(); - var cache = this._getCache(pDomain); - if (pDomain) { - domain = domain.concat(pDomain || []); - } - if (loadMore) { - var minMessageID = cache.messages[0].getID(); - domain = [['id', '<', minMessageID]].concat(domain); - } - return this._rpc({ - model: 'mail.message', - method: 'message_fetch', - args: [domain], - kwargs: this._getFetchMessagesKwargs(), - }).then(function (messages) { - if (!cache.allHistoryLoaded) { - cache.allHistoryLoaded = messages.length < self._FETCH_LIMIT; - } - cache.loaded = true; - _.each(messages, function (message) { - self.call('mail_service', 'addMessage', message, { - silent: true, - domain: pDomain, - }); - }); - cache = self._getCache(pDomain || []); - return cache.messages; - }); - }, - /** - * Get thread content from the cache - * Useful to get cached messages. - * - * @private - * @param {Array} domain - * @return {Object|undefined} - */ - _getCache: function (domain) { - var stringifiedDomain = JSON.stringify(domain || []); - if (!this._cache[stringifiedDomain]) { - this._cache[stringifiedDomain] = { - allHistoryLoaded: false, - loaded: false, - messages: [], - }; - } - return this._cache[stringifiedDomain]; - }, - /** - * Get the kwargs that are passed to the server with the 'message_fetch' - * RPC. - * - * @private - * @returns {Object} - */ - _getFetchMessagesKwargs: function () { - return { - limit: this._FETCH_LIMIT, - context: session.user_context - }; - }, - /** - * Get the domain to fetch all the messages in the current thread - * - * @abstract - * @private - * @returns {Array} - */ - _getThreadDomain: function () {}, -}); - -return SearchableThread; - -}); |
