summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/threads/thread.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/js/models/threads/thread.js')
-rw-r--r--addons/mail/static/src/js/models/threads/thread.js155
1 files changed, 63 insertions, 92 deletions
diff --git a/addons/mail/static/src/js/models/threads/thread.js b/addons/mail/static/src/js/models/threads/thread.js
index 5fcd0285a82..c9dda28dd93 100644
--- a/addons/mail/static/src/js/models/threads/thread.js
+++ b/addons/mail/static/src/js/models/threads/thread.js
@@ -5,7 +5,6 @@ var emojis = require('mail.emojis');
var AbstractThread = require('mail.model.AbstractThread');
var mailUtils = require('mail.utils');
-var Mixins = require('web.mixins');
var ServicesMixin = require('web.ServicesMixin');
/**
@@ -15,7 +14,7 @@ var ServicesMixin = require('web.ServicesMixin');
*
* In particular, channels and mailboxes are two different kinds of threads.
*/
-var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
+var Thread = AbstractThread.extend(ServicesMixin, {
/**
* @override
@@ -27,15 +26,9 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
* @param {string} [params.data.type]
*/
init: function (params) {
- Mixins.EventDispatcherMixin.init.call(this, arguments);
- this.setParent(params.parent);
this._super.apply(this, arguments);
// threads are not detached by default
this._detached = false;
- // if this._massMailing is set, display subject on messages, use
- // extended composer and show "Send by messages by email" on discuss
- // sidebar
- this._massMailing = false;
// on 1st request to getPreview, fetch data if incomplete. Otherwise it
// means that there is no message in this channel.
this._previewed = false;
@@ -49,13 +42,6 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
//--------------------------------------------------------------------------
/**
- * Add a message to this thread.
- *
- * @abstract
- * @param {mail.model.Message} message
- */
- addMessage: function (message) {},
- /**
* Updates the _detached state of the thread. Must be overriden to reflect
* the new state in the interface.
*/
@@ -140,7 +126,7 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
return {
id: this.getID(),
imageSRC: '/mail/static/src/img/smiley/avatar.jpg',
- isChat: this.isChat(),
+ isTwoUserThread: this.isTwoUserThread(),
status: this.getStatus(),
title: this.getName(),
unreadCounter: this.getUnreadCounter(),
@@ -189,16 +175,6 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
*/
incrementNeedactionCounter: function () {},
/**
- * Increment the unread counter of this thread by 1 unit, and warn that the
- * counter has been changed.
- *
- * @override
- */
- incrementUnreadCounter: function () {
- this._super.apply(this, arguments);
- this._warnUpdatedUnreadCounter();
- },
- /**
* States whether the thread should be auto-selected on creation
*
* Note that this is not of the responsibility of the thread: it only
@@ -223,17 +199,6 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
return false;
},
/**
- * States whether this thread is a chat or not. In particular, public and
- * private channels are not chat, but DMs and Livechats are chats. Chats
- * are threads used for communication between two users.
- * By default, any thread is not a chat
- *
- * @returns {boolean}
- */
- isChat: function () {
- return false;
- },
- /**
* States whether this thread is detached or not.
* A thread that is detached must have a thread window linked to itself.
*
@@ -256,10 +221,12 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
* This is a server-side setting, that determine the type of composer that
* is used (basic or extended composer).
*
+ * By default, thread have not mass-mailings feature set.
+ *
* @return {boolean}
*/
isMassMailing: function () {
- return this._massMailing;
+ return false;
},
/**
@@ -277,7 +244,18 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
*
* @returns {boolean}
*/
- isModerator: function () {
+ isMyselfModerator: function () {
+ return false;
+ },
+ /**
+ * States whether this is a two-user thread or not. In particular, public
+ * and private channels are not two-user threads, but DMs and Livechats are
+ * two-user threads. Two-user threads are used for communication between
+ * two users. By default, any thread is not two-user thread.
+ *
+ * @returns {boolean}
+ */
+ isTwoUserThread: function () {
return false;
},
/**
@@ -294,29 +272,61 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
markAsPreviewed: function () {
this._previewed = true;
},
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
/**
- * Mark the thread as read, which resets the unread counter to 0.
- *
- * @returns {$.Promise} resolved
+ * @abstract
+ * @private
+ * @return {$.Promise}
*/
- markAsRead: function () {
- if (this._unreadCounter > 0) {
- this.resetUnreadCounter();
- }
+ _fetchMessages: function () {
return $.when();
},
/**
+ * Replace character representations of emojis by their unicode
+ * representation in the provided HTML string. Note that the provided html
+ * string is altered by this function.
+ *
+ * @param {string} htmlString
+ * @returns {string}
+ */
+ _generateEmojis: function (htmlString) {
+ _.each(emojis, function (emoji) {
+ _.each(emoji.sources, function (source) {
+ var escapedSource = String(source).replace(/([.*+?=^!:${}()|[\]/\\])/g, '\\$1');
+ var regexp = new RegExp("(\\s|^)(" + escapedSource + ")(?=\\s|$)", 'g');
+ htmlString = htmlString.replace(regexp, '$1' + emoji.unicode);
+ });
+ });
+ return htmlString;
+ },
+ /**
+ * Increment the unread counter of this thread by 1 unit, and warn that the
+ * counter has been changed.
+ *
+ * @override
+ * @private
+ */
+ _incrementUnreadCounter: function () {
+ this._super.apply(this, arguments);
+ this._warnUpdatedUnreadCounter();
+ },
+ /**
* Post a message on the thread.
*
* This method must be completed by concrete threads,
* As it currently only pre-process the messages at the moment.
*
* @abstract
+ * @private
* @param {Object} data
* @returns {$.Promise<Object>} resolved with the message object to be sent
* to the server
*/
- postMessage: function (data) {
+ _postMessage: function (data) {
// This message will be received from the mail composer as html content
// subtype but the urls will not be linkified. If the mail composer
// takes the responsibility to linkify the urls we end up with double
@@ -334,58 +344,18 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
if ('subject' in data) {
messageData.subject = data.subject;
}
- return $.when(messageData);
- },
- /**
- * Overrides the method so that it also warns that the counter has been
- * changed on this thread.
- *
- * @override
- * @private
- */
- resetUnreadCounter: function () {
- this._super.apply(this, arguments);
- this._warnUpdatedUnreadCounter();
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * @abstract
- * @private
- * @return {$.Promise}
- */
- _fetchMessages: function () {
- return $.when();
- },
- /**
- * Replace character representations of emojis by their unicode
- * representation in the provided HTML string. Note that the provided html
- * string is altered by this function.
- *
- * @param {string} htmlString
- * @returns {string}
- */
- _generateEmojis: function (htmlString) {
- _.each(emojis, function (emoji) {
- _.each(emoji.sources, function (source) {
- var escapedSource = String(source).replace(/([.*+?=^!:${}()|[\]/\\])/g, '\\$1');
- var regexp = new RegExp("(\\s|^)(" + escapedSource + ")(?=\\s|$)", 'g');
- htmlString = htmlString.replace(regexp, '$1' + emoji.unicode);
- });
+ return this._super.apply(this, arguments).then(function () {
+ return $.when(messageData);
});
- return htmlString;
},
/**
- * Warn on the chat bus that the unread counter has been updated
+ * Warn on the mail bus that the unread counter has been updated
*
+ * @override
* @private
*/
_warnUpdatedUnreadCounter: function () {
- this.call('mail_service', 'getMailBus')
- .trigger('update_thread_unread_counter', this);
+ this.call('mail_service', 'getMailBus').trigger('update_thread_unread_counter', this);
},
/**
* Warn other mail components that the window state of this thread has
@@ -393,6 +363,7 @@ var Thread = AbstractThread.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
*
* @private
* @param {Object} [options={}]
+ * @param {boolean} [options.passively=false]
*/
_warnUpdatedWindowState: function (options) {
options = options || {};