summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/chat_manager.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2015-11-30 10:30:02 +0100
committerAaron Bohy <aab@odoo.com>2015-12-03 11:21:47 +0100
commit33ac65c805c30fafac4e2cf5490c57c7eaf74b4a (patch)
treeecfa65800a25234ee2084e9f44a28e5b3ea0ccda /addons/mail/static/src/js/chat_manager.js
parent6e96da625560d0a074ca61d57ec4db59a2443e47 (diff)
[FIX] mail: redirection handling in chat windows
- clicking on a channel mention (or a user) from a chat window opens a new chat window for that channel - clicking on any other link in a chat window correctly opens the corresponding document 2 minor changes were required: - use do_show() instead of on_reverse_breadcrumb() to update control panel and url in client action, as other actions can be stacked over the client action, e.g. by clicking on a document link in a chat window. In that case, the on_reverse_breadcrumb callback wouldn't be set, and thus the control panel and url wouldn't be updated by coming back to client action using the breadcrumbs. - channel_join() now checks whether or not the channel has already been joined (i.e. if it is in the JS cache) before performing the RPC. This check was performed by each caller, so this simplifies the code.
Diffstat (limited to 'addons/mail/static/src/js/chat_manager.js')
-rw-r--r--addons/mail/static/src/js/chat_manager.js55
1 files changed, 47 insertions, 8 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index e8a2ad3951e..adf1b5f6b57 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -15,6 +15,7 @@ var preview_msg_max_size = 50;
var MessageModel = new Model('mail.message', session.context);
var ChannelModel = new Model('mail.channel', session.context);
+var UserModel = new Model('res.users', session.context);
// Private model
//----------------------------------------------------------------------------------
@@ -399,7 +400,7 @@ function on_needaction_notification (message) {
function on_channel_notification (message) {
var def;
- if ((message.channel_ids.length === 1) && !chat_manager.get_channel(message.channel_ids[0])) {
+ if (message.channel_ids.length === 1) {
def = chat_manager.join_channel(message.channel_ids[0], {autoswitch: false});
} else {
def = $.when();
@@ -638,15 +639,21 @@ var chat_manager = {
},
join_channel: function (channel_id, options) {
if (channel_id in channel_defs) {
+ // prevents concurrent calls to channel_join_and_get_info
return channel_defs[channel_id];
}
- var def = ChannelModel
- .call('channel_join_and_get_info', [[channel_id]])
- .then(function (result) {
- add_channel(result, options);
- });
- channel_defs[channel_id] = def;
- return def;
+ var channel = this.get_channel(channel_id);
+ if (channel) {
+ // channel already joined
+ channel_defs[channel_id] = $.when(channel);
+ } else {
+ channel_defs[channel_id] = ChannelModel
+ .call('channel_join_and_get_info', [[channel_id]])
+ .then(function (result) {
+ return add_channel(result, options);
+ });
+ }
+ return channel_defs[channel_id];
},
unsubscribe: function (channel) {
@@ -671,6 +678,38 @@ var chat_manager = {
channel.is_folded = !channel.is_folded;
});
},
+ /**
+ * Special redirection handling for given model and id
+ *
+ * If the model is res.partner, and there is a user associated with this
+ * partner which isn't the current user, open the DM with this user.
+ * Otherwhise, open the record's form view, if this is not the current user's.
+ */
+ redirect: function (res_model, res_id, dm_redirection_callback) {
+ var self = this;
+ var redirect_to_document = function (res_model, res_id) {
+ web_client.do_action({
+ type:'ir.actions.act_window',
+ view_type: 'form',
+ view_mode: 'form',
+ res_model: res_model,
+ views: [[false, 'form']],
+ res_id: res_id,
+ });
+ };
+ if (res_model === "res.partner") {
+ var domain = [["partner_id", "=", res_id]];
+ UserModel.call("search", [domain]).then(function (user_ids) {
+ if (user_ids.length && user_ids[0] !== session.uid) {
+ self.create_channel(res_id, 'dm').then(dm_redirection_callback || function () {});
+ } else if (!user_ids.length) {
+ redirect_to_document(res_model, res_id);
+ }
+ });
+ } else {
+ redirect_to_document(res_model, res_id);
+ }
+ },
};
// Initialization