summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/threads/abstract_thread.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-08-11 20:30:51 +0200
committerAlexandre Kühn <aku@odoo.com>2018-08-13 14:17:27 +0200
commitf2302dfb27dd7f6a0dee7c65ab75b62a01706264 (patch)
treed58fef9e2e8a5b98c0680f28fc92e24992236029 /addons/mail/static/src/js/models/threads/abstract_thread.js
parent3de97f168956a7c22c3af6b72950cf28554f4139 (diff)
[REF][FIX] mail, im_livechat: various improvements (JS)
This commit makes a lot of small improvements of the JS of mail and related modules. A. Mail Manager --------------- im_support: - [REF] Slightly more robust way to determine a support message, so that it more reliably falls back on default kind of message (i.e. support channel UUID should be clearly set). mail: - [REF] Improved method names for readability purposes. Some examples: - `fetchFromServer` becomes `fetchMailStateFromServer` - `_initialize{*}` becomes `_update{*}FromServer` - `_isModerator` becomes `_isMyselfModerator` - [REF] Use 'template' pattern design to make Include on Mail Manager much more robust. In particular, the flow is always as follow: 1. Initialize internal state. 2. Listen on buses. 3. Fetch mail data from server. - [REF] Improved workflow for thread window workflow (Shorter & more readable). B. Mail Tests ------------- - [REF] Thread Window Tests crashes with clean message when there are some thread windows open before running the tests. C. (Model) Message ------------------ - [REF] Improved method names for readability purposes (e.g. `isAuthor` becomes `isMyselfAuthor`). D. (Model) Thread ----------------- - [REF] Improved `init` parameters on each kind of thread. - [REF] 'Thread With Cache' has been renamed to 'Searchable Thread': it embraces all kinds of threads that can be used with the search view. - [REF] 'DM' has been renamed to 'DM Chat' (for clarity). - [IMP] New Livechat model in the backend. - [REF] No more direct instances of the Channel class: public and private channels are now 'Multi-User' channels, while DM Chat and Livechat are 'Two-User' channels: This change has been made so that instances of classes always have direct classes as "leaf" in the Class modeling. It eases making changes to a certain model without being too constrained by another model. - [REF] As a consequence of above changed, the method `isChat` has been renamed to `isTwoUserThread`. This is to avoid confusion with the terminology 'chat', which is more like a shortcut for 'quick real- time conversation'. In other words, the property of 'chat' depends of the way to interact on a thread, not of the intrinsic type of the thread. Still, some parts have kept the terminology 'chat', such as in the systray messagin menu. - [IMP] Added `message_added` and `message_posted` hooks, which may be useful to easily hook on those events. E. Thread Widget ---------------- - [REF] Now uses a `mail.model.AbstractThread` for the rendering of a thread, instead of a list of `{mail.model.AbstractMessage}`. - [FIX] Stick thread scroll height to bottom on new rendering, if it was previously at the bottom of the thread. - [REF] Option ORDER has its meaning changed: it now refers to the chronological order of messages in the thread, in which DESC means 'from top to bottom', while ASC means 'from bottom to top'. - [REF] Improved doc on templates, in particular with the option `ORDER`. F. Thread Window ---------------- - [REF] Moved more logic to thread windows, which were previously in Mail Window Manager. - [REF] Now hides the thread widget attribute. So instead of `threadWindow.threadWidget.isAtBottom()`, it uses `threadWindow.isAtBottom()`. - [FIX] New received messages when not having focus on Odoo tab should always make the corresponding thread windows "passive" (i.e. windows that keep threads unread until click on them). - [FIX] Blank thread window (i.e. 'New message' TW) correctly opens Discuss with 'Inbox' when clicking on 'Expand' Button in the title - [FIX] Do not display the composer for channels with property 'mass-mailing' set in thread windows. G. (Website) Livechat --------------------- - [REF] Some `trigger` have been turned into `trigger_up`. - [REF] Some logic has been moved to models (e.g. `{im_livechat.model.WebsiteLivechat}`), from `{im_livechat.im_livechat.LivechatButton}`. - [FIX] New messages should be received in real-time. The longpolling was broken with a recent refactoring on bus service (6448420c5dd160470e465dee7729d19d8d5e7bab).
Diffstat (limited to 'addons/mail/static/src/js/models/threads/abstract_thread.js')
-rw-r--r--addons/mail/static/src/js/models/threads/abstract_thread.js88
1 files changed, 81 insertions, 7 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 67929517ed4..fb6695c6a6c 100644
--- a/addons/mail/static/src/js/models/threads/abstract_thread.js
+++ b/addons/mail/static/src/js/models/threads/abstract_thread.js
@@ -2,6 +2,7 @@ odoo.define('mail.model.AbstractThread', function (require) {
"use strict";
var Class = require('web.Class');
+var Mixins = require('web.mixins');
/**
* Abstract thread is the super class of all threads, either backend threads
@@ -9,15 +10,20 @@ var Class = require('web.Class');
*
* Abstract threads contain abstract messages
*/
-var AbstractThread = Class.extend({
+var AbstractThread = Class.extend(Mixins.EventDispatcherMixin, {
/**
* @param {Object} params
* @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 {Object} params.parent Object with the event-dispatcher mixin
+ * (@see {web.mixins.EventDispatcherMixin})
*/
init: function (params) {
+ Mixins.EventDispatcherMixin.init.call(this, arguments);
+ this.setParent(params.parent);
+
this._folded = false; // threads are unfolded by default
this._id = params.data.id;
this._name = params.data.name;
@@ -30,6 +36,15 @@ var AbstractThread = Class.extend({
//--------------------------------------------------------------------------
/**
+ * Add a message to this thread.
+ *
+ * @param {mail.model.AbstractMessage} message
+ */
+ addMessage: function (message) {
+ this._addMessage.apply(this, arguments);
+ this.trigger('message_added', message);
+ },
+ /**
* Updates the folded state of the thread
*
* @param {boolean} folded
@@ -88,12 +103,6 @@ var AbstractThread = Class.extend({
return !_.isEmpty(this.getMessages());
},
/**
- * Increments the unread counter of this thread by 1 unit.
- */
- incrementUnreadCounter: function () {
- this._unreadCounter++;
- },
- /**
* States whether this thread is folded or not.
*
* @return {boolean}
@@ -102,11 +111,76 @@ var AbstractThread = Class.extend({
return this._folded;
},
/**
+ * 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}
+ */
+ markAsRead: function () {
+ if (this._unreadCounter > 0) {
+ return this._markAsRead();
+ }
+ return $.when();
+ },
+ /**
+ * Post a message on this thread
+ *
+ * @returns {$.Promise} resolved with the message object to be sent to the
+ * server
+ */
+ postMessage: function () {
+ return this._postMessage.apply(this, arguments)
+ .then(this.trigger.bind(this, 'message_posted'));
+ },
+ /**
* Resets the unread counter of this thread to 0.
*/
resetUnreadCounter: function () {
this._unreadCounter = 0;
},
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * Add a message to this thread.
+ *
+ * @abstract
+ * @private
+ * @param {mail.model.AbstractMessage} message
+ */
+ _addMessage: function (message) {},
+ /**
+ * Increments the unread counter of this thread by 1 unit.
+ *
+ * @private
+ */
+ _incrementUnreadCounter: function () {
+ this._unreadCounter++;
+ },
+ /**
+ * Mark the thread as read
+ *
+ * @private
+ * @returns {$.Promise}
+ */
+ _markAsRead: function () {
+ this.resetUnreadCounter();
+ this._warnUpdatedUnreadCounter();
+ return $.when();
+ },
+ /**
+ * Post a message on this thread
+ *
+ * @abstract
+ * @private
+ * @returns {$.Promise} resolved with the message object to be sent to the
+ * server
+ */
+ _postMessage: function () {
+ return $.when();
+ },
});
return AbstractThread;