diff options
Diffstat (limited to 'addons/mail/static/src/js/services/chat_manager.js')
| -rw-r--r-- | addons/mail/static/src/js/services/chat_manager.js | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/addons/mail/static/src/js/services/chat_manager.js b/addons/mail/static/src/js/services/chat_manager.js index b7c46f2d4c1..fb4b6672bc6 100644 --- a/addons/mail/static/src/js/services/chat_manager.js +++ b/addons/mail/static/src/js/services/chat_manager.js @@ -16,11 +16,11 @@ var _lt = core._lt; var LIMIT = 30; // max number of fetched messages from the server var PREVIEW_MSG_MAX_SIZE = 350; // optimal for native english speakers -var ODOOBOT_ID = "ODOOBOT"; // default author_id for messages +var ODOOBOT_ID = "ODOOBOT"; // default author_id for messages /** * This service handles everything about chat channels and messages. - * + * * There are basically two points of entry: * * 1. Calling a public method by means of 'this.call' @@ -54,13 +54,13 @@ var ChatManager = AbstractService.extend({ this.pinnedDmPartners = []; // partner_ids we have a pinned DM with this.discussOpen = false; - this.chatBus = new Bus(); + this.chatBus = new Bus(this); this.busBus = this.call('bus_service', 'getBus'); this.chatBus.on('discuss_open', null, function (open) { self.discussOpen = open; }); - + this.busBus.on('notification', this, this._onNotification); this.busBus.on('window_focus', this, this._onWindowFocus); @@ -77,12 +77,12 @@ var ChatManager = AbstractService.extend({ this._isReady = this._initMessaging(); + // Add static channels this._addChannel({ id: "channel_inbox", name: _lt("Inbox"), type: "static", }, { displayNeedactions: true }); - this._addChannel({ id: "channel_starred", name: _lt("Starred"), @@ -181,7 +181,7 @@ var ChatManager = AbstractService.extend({ * Returns a channel corresponding to the given id. * * @param {string|integer} id e.g. 'channel_inbox', 'channel_starred' - * @return {Object|undefined} channel + * @return {Object|undefined} the channel, if it exists */ getChannel: function (id) { return _.findWhere(this.channels, {id: id}); @@ -189,7 +189,7 @@ var ChatManager = AbstractService.extend({ /** * Returns a list of channels * - * @return {Object[]} + * @return {Object[]} list of channels */ getChannels: function () { return _.clone(this.channels); @@ -282,12 +282,13 @@ var ChatManager = AbstractService.extend({ * Show the list of available commands next to a message (e.g. star) * * @param {Object} channel - * @return {Array} + * @return {Array} list of commands */ getCommands: function (channel) { - return _.filter(this.commands, function (command) { + var commands = _.filter(this.commands, function (command) { return !command.channel_types || _.contains(command.channel_types, channel.server_type); }); + return commands; }, /** * Returns the record id of ir.ui.menu for Discuss @@ -309,7 +310,7 @@ var ChatManager = AbstractService.extend({ /** * Returns list of emojis Objects * - * @return {Object[]} + * @return {Object[]} list of emojis * ['id', 'source', 'unicode_source', 'substitution', 'description'] */ getEmojis: function () { @@ -319,9 +320,10 @@ var ChatManager = AbstractService.extend({ * Get the last seen message for a given channel * * @param {Object} channel - * @return {Object} Message Object + * @return {Object|undefined} last seen Message Object (if any) */ getLastSeenMessage: function (channel) { + var result; if (channel.last_seen_message_id) { var messages = channel.cache['[]'].messages; var msg = _.findWhere(messages, {id: channel.last_seen_message_id}); @@ -332,9 +334,10 @@ var ChatManager = AbstractService.extend({ msg = messages[i]; i++; } - return msg; + result = msg; } } + return result; }, /** * Get all listeners of a channel. @@ -378,22 +381,22 @@ var ChatManager = AbstractService.extend({ * Gets message from its id * * @param {integer} msgID - * @return {Object|undefined} Message Object + * @return {Object|undefined} Message Object (if any) */ getMessage: function (msgID) { return _.findWhere(this.messages, {id: msgID}); }, /** * Gets messages from channel or ids or record (model and res_id): - * + * * 1. From channel if we have 'channelID' in options * 2. From ids if we have 'ids' in options * 3. From model if we have 'model' and 'res_id' in options - * + * * Rule of precedence: - * + * * 'channelID' < 'ids' < 'model' and 'res_id' - * + * * If we have none of the cases above, we return an empty list. * * @param {Object} [options] @@ -451,7 +454,7 @@ var ChatManager = AbstractService.extend({ * Returns the number of messages received from followed channels * + all messages where the current user is notified. * - * @return {integer} + * @return {integer} needaction counter */ getNeedactionCounter: function () { return this.needactionCounter; @@ -459,7 +462,7 @@ var ChatManager = AbstractService.extend({ /** * Gets the number of starred message * - * @return {integer} + * @return {integer} starred counter */ getStarredCounter: function () { return this.starredCounter; @@ -467,7 +470,7 @@ var ChatManager = AbstractService.extend({ /** * Gets the number of conversation which contains unread messages * - * @return {integer} + * @return {integer} unread conversation counter */ getUnreadConversationCounter: function () { return this.unreadConversationCounter; @@ -491,7 +494,7 @@ var ChatManager = AbstractService.extend({ /** * join an existing channel * See @createChannel to join a new channel - * + * * @param {integer} channelID * @param {Object} [options] * @return {$.Promise<Object>} resolved with channel object @@ -593,7 +596,7 @@ var ChatManager = AbstractService.extend({ }, /** * Open the channel: - * + * * 1. If discuss is opened, asks discuss to open the channel * 2. Otherwise, asks the chat_window_manager to detach the channel * @@ -604,14 +607,14 @@ var ChatManager = AbstractService.extend({ }, /** * Prepares and sends a message to the server: - * + * * 1. Either the message is posted on a channel * 2. Or the message is posted in a model's record (chatter) * * Rule of precedence: - * + * * 'channelID' < 'model' & 'res_id' - * + * * If options as none of these parameters, do nothing and return * a promise no resolved item. * @@ -856,7 +859,7 @@ var ChatManager = AbstractService.extend({ * @param {string} [data.state] e.g. 'open', 'folded' * @param {Object|integer} [options=undefined] * @param {boolean} [options.silent] - * @return {Object} the newly or already exisiting channel + * @return {Object} the newly or already existing channel */ _addChannel: function (data, options) { options = typeof options === "object" ? options : {}; @@ -909,7 +912,7 @@ var ChatManager = AbstractService.extend({ * @param {Object} data message data * @param {integer} data.id * @param {Object} [options] - * @param {Array} [options.domain] + * @param {Array} [options.domain] * @param {boolean} [options.increment_unread] whether we should increment * the unread_counter of channel. * @param {boolean} [options.silent] whether it should inform in the chatBus @@ -1134,6 +1137,7 @@ var ChatManager = AbstractService.extend({ } } }); + self.busBus.start_polling(); }); }, @@ -1466,7 +1470,7 @@ var ChatManager = AbstractService.extend({ } }, /** - * Updates channel_inbox when a message has marked as read. + * Updates channel_inbox when a message has marked as read. * * @private * @param {Object} data @@ -1746,6 +1750,8 @@ var ChatManager = AbstractService.extend({ }); +core.serviceRegistry.add('chat_manager', ChatManager); + return ChatManager; }); |
