diff options
Diffstat (limited to 'addons/mail/static/src/js/client_action.js')
| -rw-r--r-- | addons/mail/static/src/js/client_action.js | 80 |
1 files changed, 17 insertions, 63 deletions
diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js index b96e9af6777..ae032b4ece1 100644 --- a/addons/mail/static/src/js/client_action.js +++ b/addons/mail/static/src/js/client_action.js @@ -190,14 +190,11 @@ var ChatAction = Widget.extend(ControlPanelMixin, { }); this.$buttons.on('click', '.o_mail_chat_button_unstar_all', chat_manager.unstar_all); - this.thread.on('redirect', this, this.on_redirect); + this.thread.on('redirect', this, function (res_model, res_id) { + chat_manager.redirect(res_model, res_id, this.set_channel.bind(this)); + }); this.thread.on('redirect_to_channel', this, function (channel_id) { - var channel = chat_manager.get_channel(channel_id); - if (channel) { - this.set_channel(channel); - } else { - chat_manager.join_channel(channel_id); - } + chat_manager.join_channel(channel_id).then(this.set_channel.bind(this)); }); this.thread.on('load_more_messages', this, this.load_more_messages); this.thread.on('mark_as_read', this, function (message_id) { @@ -375,7 +372,6 @@ var ChatAction = Widget.extend(ControlPanelMixin, { self.$buttons .find('.o_mail_chat_button_unstar_all') .toggle(channel.id === "channel_starred"); - self.update_cp(); self.$('.o_chat_composer').toggle(channel.type !== 'static'); @@ -393,6 +389,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, { self.$('.o_mail_chat_sidebar').hide(); } + self.update_cp(); self.action_manager.do_push_state({ action: self.action.id, active_id: self.channel.id, @@ -466,7 +463,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, { var oldest_msg_selector = '.o_thread_message[data-message-id="' + oldest_msg_id + '"]'; var offset = -framework.getPosition(document.querySelector(oldest_msg_selector)).top; return chat_manager - .fetch_more(this.channel, this.domain) + .get_messages({channel_id: this.channel.id, domain: this.domain, load_more: true}) .then(function(result) { if (self.messages_separator_position === 'top') { self.messages_separator_position = undefined; // reset value to re-compute separator position @@ -489,6 +486,15 @@ var ChatAction = Widget.extend(ControlPanelMixin, { }); }, + do_show: function () { + this._super.apply(this, arguments); + this.update_cp(); + this.action_manager.do_push_state({ + action: this.action.id, + active_id: this.channel.id, + }); + }, + on_search: function (domains) { var result = pyeval.sync_eval_domains_and_contexts({ domains: domains @@ -498,60 +504,10 @@ var ChatAction = Widget.extend(ControlPanelMixin, { this.fetch_and_render_thread(); }, - /** - * Callback performed on o_mail_redirect element clicked - * - * 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. - */ - on_redirect: function (res_model, res_id) { - var self = this; - var redirect_to_document = function (res_model, res_id) { - self.action_manager.do_push_state({ - model: res_model, - id: res_id, - }); - self.do_action({ - type:'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [[false, 'form']], - res_id: res_id, - }, { - on_reverse_breadcrumb: self.on_reverse_breadcrumb, - }); - }; - - if (res_model === "res.partner") { - var domain = [["partner_id", "=", res_id]]; - new Model('res.users').call("search", [domain]).then(function (user_ids) { - if (user_ids.length && user_ids[0] !== session.uid) { - chat_manager.create_channel(res_id, 'dm').then(function (channel) { - if (!self.channel || self.channel.id !== channel.id) { - self.set_channel(channel); - } - }); - } else { - redirect_to_document(res_model, res_id); - } - }); - } else { - redirect_to_document(res_model, res_id); - } - }, - on_reverse_breadcrumb: function () { - this.update_cp(); // do not reload the client action, just display it, but a refresh of the control panel is needed. - this.action_manager.do_push_state({ - action: this.action.id, - active_id: this.channel.id, - }); - }, on_post_message: function (message) { - message.channel_id = this.channel.id; + var options = {channel_id: this.channel.id}; chat_manager - .post_message(message) + .post_message(message, options) .fail(function () { // todo: display notification }); @@ -615,8 +571,6 @@ var ChatAction = Widget.extend(ControlPanelMixin, { res_id: this.channel.id, views: [[false, 'form']], target: 'current' - }, { - on_reverse_breadcrumb: this.on_reverse_breadcrumb, }); }, }); |
