[IMP] im_livechat,mail: sort livechat channels in Discuss

by date of last message in channel, desc.
This commit is contained in:
Aaron Bohy
2016-06-22 10:10:46 +02:00
parent 90f9c09eec
commit db99c65f7b
4 changed files with 46 additions and 3 deletions
+6 -1
View File
@@ -47,11 +47,16 @@ class MailChannel(models.Model):
partner_name = self.env['res.partner'].browse(self.env.context.get('im_livechat_operator_partner_id')).name_get()[0]
for channel_info in channel_infos:
channel_info['operator_pid'] = partner_name
# add the anonymous name
channel_infos_dict = dict((c['id'], c) for c in channel_infos)
for channel in self:
# add the anonymous name
if channel.anonymous_name:
channel_infos_dict[channel.id]['anonymous_name'] = channel.anonymous_name
# add the last message date
if channel.channel_type == 'livechat':
last_msg = self.env['mail.message'].search([("channel_ids", "in", [channel.id])], limit=1)
if last_msg:
channel_infos_dict[channel.id]['last_message_date'] = last_msg.date
return channel_infos_dict.values()
@api.model
@@ -0,0 +1,31 @@
odoo.define('im_livechat.chat_client_action', function (require) {
"use strict";
require('mail.chat_client_action');
var chat_manager = require('mail.chat_manager');
var core = require('web.core');
core.action_registry.get('mail.chat.instant_messaging').include({
_render_sidebar: function (options) {
// Override to sort livechat channels by last message's date
var channel_partition = _.partition(options.channels, function (channel) {
return channel.type === 'livechat';
});
channel_partition[0].sort(function (c1, c2) {
return c2.last_message_date.diff(c1.last_message_date);
});
options.channels = channel_partition[0].concat(channel_partition[1]);
return this._super(options);
},
});
chat_manager.bus.on('new_message', null, function (msg) {
_.each(msg.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id);
if (channel) {
channel.last_message_date = msg.date; // update the last message's date of the channel
}
});
});
});
@@ -273,6 +273,9 @@ function make_channel (data, options) {
} else if ('anonymous_name' in data) {
channel.name = data.anonymous_name;
}
if (data.last_message_date) {
channel.last_message_date = moment(time.str_to_datetime(data.last_message_date));
}
channel.is_chat = !channel.type.match(/^(public|private|static)$/);
if (data.message_unread_counter) {
update_channel_unread_counter(channel, data.message_unread_counter);
+6 -2
View File
@@ -293,11 +293,11 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
render_sidebar: function () {
var self = this;
var $sidebar = $(QWeb.render("mail.chat.Sidebar", {
var $sidebar = this._render_sidebar({
active_channel_id: this.channel ? this.channel.id: undefined,
channels: chat_manager.get_channels(),
needaction_counter: chat_manager.get_needaction_counter(),
}));
});
this.$(".o_mail_chat_sidebar").html($sidebar.contents());
this.$('.o_mail_add_channel[data-type=public]').find("input").autocomplete({
@@ -349,6 +349,10 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
});
},
_render_sidebar: function (options) {
return $(QWeb.render("mail.chat.Sidebar", options));
},
render_snackbar: function (template, context, timeout) {
if (this.$snackbar) {
this.$snackbar.remove();