summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/threads/thread.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-07-04 15:57:03 +0200
committerAlexandre Kühn <aku@odoo.com>2018-07-19 13:58:34 +0200
commit915da49d173e9ab8d0c6d94cbeec124c83d23fc7 (patch)
treed7fe30d4a4c7f1a6923b88c91ac98582ee6500f4 /addons/mail/static/src/js/models/threads/thread.js
parentec8c505bc1c9ec21939e9ffef53a9cc6f63f30c7 (diff)
[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)
Diffstat (limited to 'addons/mail/static/src/js/models/threads/thread.js')
-rw-r--r--addons/mail/static/src/js/models/threads/thread.js74
1 files changed, 33 insertions, 41 deletions
diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js
index de2c6628d67..5a376f8f7e2 100644
--- a/addons/mail/static/src/js/models/threads/thread.js
+++ b/addons/mail/static/src/js/models/threads/thread.js
@@ -2,9 +2,9 @@ odoo.define('mail.model.Thread', function (require) {
"use strict";
var emojis = require('mail.emojis');
+var AbstractThread = require('mail.model.AbstractThread');
var mailUtils = require('mail.utils');
-var Class = require('web.Class');
var Mixins = require('web.mixins');
var ServicesMixin = require('web.ServicesMixin');
@@ -15,20 +15,20 @@ var ServicesMixin = require('web.ServicesMixin');
*
* In particular, channels and mailboxes are two different kinds of threads.
*/
-var Thread = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
- /**
- * @param {mail.Manager} parent
- * @param {Object} data
- * @param {string} [data.channel_type]
- * @param {integer|string} data.id
- * @param {string} data.name
- * @param {string} [data.type]
- */
- init: function (parent, data) {
+var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
+ /**
+ * @override
+ * @param {Object} params
+ * @param {mail.Manager} param.parent
+ * @param {Object} params.data
+ * @param {string} [params.data.channel_type]
+ * @param {string} params.data.name
+ * @param {string} [params.data.type]
+ */
+ init: function (params) {
+ this._super.apply(this, arguments);
Mixins.EventDispatcherMixin.init.call(this, arguments);
- this.setParent(parent);
-
- this._id = data.id;
+ this.setParent(params.parent);
// threads are not detached by default
this._detached = false;
@@ -38,11 +38,11 @@ var Thread = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
// extended composer and show "Send by messages by email" on discuss
// sidebar
this._massMailing = false;
- this._name = data.name;
+ this._name = params.data.name;
// on 1st request to getPreview, fetch data if incomplete. Otherwise it
// means that there is no message in this channel.
this._previewed = false;
- this._type = data.type || data.channel_type;
+ this._type = params.data.type || params.data.channel_type;
// any new message that has not been read yet
this._unreadCounter = 0;
// max number of fetched messages from the server
@@ -88,6 +88,23 @@ var Thread = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
});
},
/**
+ * Fetch the list of messages in this thread.
+ * By default, a thread has no messages.
+ *
+ * Note that this method only returns some messages, as we do not want to
+ * fetch all messages of a thread at once, just to read the last message.
+ *
+ * As a result, this method fetches only some messages of the thread,
+ * starting from the last message in the thread. At most, it fetches
+ * `this.LIMIT` number of messages at a time.
+ *
+ * @abstract
+ * @returns {$.Promise<mail.model.Message[]>}
+ */
+ fetchMessages: function () {
+ return $.when([]);
+ },
+ /**
* Updates the _folded state of the thread. Must be overriden to reflect
* the new state in the interface.
*/
@@ -106,14 +123,6 @@ var Thread = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
return [];
},
/**
- * Get the ID of the thread
- *
- * @returns {integer|string} string for mailboxes (e.g. 'mailbox_inbox')
- */
- getID: function () {
- return this._id;
- },
- /**
* Get the listeners of the thread.
* By default, a thread has not listener.
*
@@ -124,23 +133,6 @@ var Thread = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
return $.when([]);
},
/**
- * Get the list of messages in this thread.
- * By default, a thread has no messages.
- *
- * Note that this method only returns some messages, as we do not want to
- * fetch all messages of a thread at once, just to read the last message.
- *
- * As a result, this method fetches only some messages of the thread,
- * starting from the last message in the thread. At most, it fetches
- * `this.LIMIT` number of messages at a time.
- *
- * @abstract
- * @returns {$.Promise<mail.model.Message[]>}
- */
- getMessages: function () {
- return $.when([]);
- },
- /**
* Get the name of this thread
*
* @returns {string|Object} object for lazy translated names with _lt