From 915da49d173e9ab8d0c6d94cbeec124c83d23fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 4 Jul 2018 15:57:03 +0200 Subject: [IMP] mail, *: template rendering with abstract thread, adapt thread instantiation, thread `getMessages`/`fetchMessages`, and create mode document thread. * = im_livechat, im_support - thread widget now uses abstract thread in `render` method - thread models have their `init` parameters changed, so that the parent may be optional - reworked 'creating a new record...' in chatter in create mode: > new model CreateModeDocumentThread, which basically is a fake document thread with a fake message for its rendering in create mode of the chatter > special rendering method of thread_widget for such case: `renderChatterCreateMode` - renamed thread methods previously named `getMessages` to `fetchMessages`: > in order to not conflict with `getMessages`, used for rendering > now, `getMessages` always get messages that are locally, while `fetchMessages` may fetch messages. TODO: - special thread model for im_livechat (rendering is broken ATM) --- .../src/js/models/threads/thread_with_cache.js | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'addons/mail/static/src/js/models/threads/thread_with_cache.js') diff --git a/addons/mail/static/src/js/models/threads/thread_with_cache.js b/addons/mail/static/src/js/models/threads/thread_with_cache.js index f25a19005f2..ef064072bbf 100644 --- a/addons/mail/static/src/js/models/threads/thread_with_cache.js +++ b/addons/mail/static/src/js/models/threads/thread_with_cache.js @@ -16,9 +16,11 @@ var session = require('web.session'); var ThreadWithCache = Thread.extend({ /** * @override - * @param {integer} [data.seen_message_id=undefined] + * @param {Object} params + * @param {Object} params.data + * @param {integer} [params.data.seen_message_id=undefined] */ - init: function (parent, data) { + init: function (params) { this._super.apply(this, arguments); this._cache = { @@ -28,7 +30,7 @@ var ThreadWithCache = Thread.extend({ messages: [], } }; - this._lastSeenMessageID = data.seen_message_id; + this._lastSeenMessageID = params.data.seen_message_id; }, //-------------------------------------------------------------------------- @@ -52,20 +54,12 @@ var ThreadWithCache = Thread.extend({ cache.messages.splice(index, 0, message); } }, - /** - * 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 {Array} [domain] * @param {boolean} [loadMore=false] */ - getMessages: function (domain, loadMore) { + fetchMessages: function (domain, loadMore) { if (loadMore) { return this._fetchMessages(domain, true); } @@ -77,11 +71,19 @@ var ThreadWithCache = Thread.extend({ } }, /** - * @private - * @return {boolean} true if there is at least a message, false otherwise + * 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 + * @return {mail.model.Message[]} */ - hasMessages: function () { - return !!(_.last(this._cache['[]'].messages)); + getMessages: function () { + return this._cache['[]'].messages; }, /** * Invalidate the caches of the thread -- cgit v1.2.3