Permalink
Browse files

changes from xdo comments

  • Loading branch information...
alexkuhn committed Dec 6, 2018
1 parent 0035415 commit 38c1f79298e8d1fa5e33ff5599e57e9dab15031a
@@ -539,10 +539,13 @@ def channel_info(self, extra_info = False):
:rtype : list(dict)
"""
channel_infos = []
my_partner_channels = self.env['mail.channel.partner']
# find the channel partner state, if logged user
if self.env.user and self.env.user.partner_id:
my_partner_channels = self.env['mail.channel.partner'].search([('partner_id', '=', self.env.user.partner_id.id), ('channel_id', 'in', self.ids)])
# all relations partner_channel on those channels
all_partner_channel = self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids)])
# all partner infos on those channels
partner_infos = all_partner_channel.mapped('partner_id').read(['id', 'name', 'email'])
# for each channel, build the information header and include the logged partner information
for channel in self:
info = {
@@ -575,28 +578,33 @@ def channel_info(self, extra_info = False):
if last_message:
info['last_message'] = last_message[0].get('last_message')
# listeners of the channel
channel_partners = all_partner_channel.filtered(lambda pc: channel.id == pc.channel_id.id)
# find the channel partner state, if logged user
partner_channel = self.env['mail.channel.partner']
if self.env.user and self.env.user.partner_id:
partner_channel = channel_partners.filtered(lambda pc: pc.partner_id.id == self.env.user.partner_id.id)
# add needaction and unread counter, since the user is logged
info['message_needaction_counter'] = channel.message_needaction_counter
info['message_unread_counter'] = channel.message_unread_counter
# add user session state, if available and if user is logged
if my_partner_channels.ids:
partner_channel = my_partner_channels.filtered(lambda c: channel.id == c.channel_id.id)
if partner_channel.ids:
if len(partner_channel) >= 1:
partner_channel = partner_channel[0]
info['state'] = partner_channel.fold_state or 'open'
info['is_minimized'] = partner_channel.is_minimized
info['custom_channel_name'] = partner_channel.custom_channel_name
# add needaction and unread counter, since the user is logged
info['message_needaction_counter'] = channel.message_needaction_counter
info['message_unread_counter'] = channel.message_unread_counter
info['members'] = self.channel_fetch_listeners(info['uuid'])
all_channel_partners = self.env['mail.channel.partner'].search([('channel_id', '=', channel.id)])
seen_partners_info = []
for channel_partner in all_channel_partners:
seen_partners_info.append({
'partner_id': channel_partner.partner_id.id,
'last_fetched_message_id': channel_partner.fetched_message_id.id,
'last_seen_message_id': channel_partner.seen_message_id.id,
})
info['seen_partners_info'] = seen_partners_info
# add members infos
partner_ids = channel_partners.mapped('partner_id').ids
info['members'] = [partner_info for partner_info in partner_infos if partner_info['id'] in partner_ids]
info['seen_partners_info'] = [{
'partner_id': cp.partner_id.id,
'fetched_message_id': cp.fetched_message_id.id,
'seen_message_id': cp.seen_message_id.id,
} for cp in channel_partners]
channel_infos.append(info)
return channel_infos
@@ -712,20 +720,19 @@ def channel_pin(self, uuid, pinned=False):
@api.multi
def channel_seen(self):
self.ensure_one()
if not self.channel_message_ids.ids:
return
last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message
self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]).write({
'seen_message_id': last_message_id,
'fetched_message_id': last_message_id,
})
data = {
'info': 'channel_seen',
'last_message_id': last_message_id,
'partner_id': self.env.user.partner_id.id,
}
self.env['bus.bus'].sendmany([[(self._cr.dbname, 'mail.channel', self.id), data]])
return last_message_id
if self.channel_message_ids.ids:
last_message_id = self.channel_message_ids.ids[0] # zero is the index of the last message
self.env['mail.channel.partner'].search([('channel_id', 'in', self.ids), ('partner_id', '=', self.env.user.partner_id.id)]).write({
'seen_message_id': last_message_id,
'fetched_message_id': last_message_id,
})
data = {
'info': 'channel_seen',
'last_message_id': last_message_id,
'partner_id': self.env.user.partner_id.id,
}
self.env['bus.bus'].sendmany([[(self._cr.dbname, 'mail.channel', self.id), data]])
return last_message_id
@api.multi
def channel_fetched(self):
@@ -39,8 +39,8 @@ var Channel = SearchableThread.extend(ChannelSeenMixin, ThreadTypingMixin, {
* moderated or not
* @param {Object[]} [params.data.partners_info=[]]
* @param {integer} [params.data.partners_info[i].partner_id]
* @param {integer} [params.data.partners_info[i].last_fetched_message_id]
* @param {integer} [params.data.partners_info[i].last_seen_message_id]
* @param {integer} [params.data.partners_info[i].fetched_message_id]
* @param {integer} [params.data.partners_info[i].seen_message_id]
* @param {string} params.data.state
* @param {string} [params.data.uuid]
* @param {Object} params.options
@@ -19,8 +19,8 @@ var ChannelSeenMixin = {
* @param {Object} params
* @param {Object[]} [params.data.partners_info=[]]
* @param {integer} [params.data.seen_partners_info[i].partner_id]
* @param {integer} [params.data.seen_partners_info[i].last_fetched_message_id]
* @param {integer} [params.data.seen_partners_info[i].last_seen_message_id]
* @param {integer|boolean} [params.data.seen_partners_info[i].fetched_message_id=false]
* @param {integer|boolean} [params.data.seen_partners_info[i].seen_message_id=false]
*/
init: function (params) {
this._seenPartnersInfo = params.data.seen_partners_info || [];
@@ -52,15 +52,15 @@ var ChannelSeenMixin = {
// seen partner IDs
var seenPartnersInfo = _.filter(otherPartnersInfo, function (info) {
return info.last_seen_message_id && info.last_seen_message_id >= message.getID();
return info.seen_message_id && info.seen_message_id >= message.getID();
});
var seenPartnerIDs = _.map(seenPartnersInfo, function (info) {
return info.partner_id;
});
// fetched partner IDs (ignore seen)
var fetchedPartnersInfo = _.filter(otherPartnersInfo, function (info) {
var lastFetchedID = info.last_fetched_message_id || info.last_seen_message_id || 0;
var lastFetchedID = info.fetched_message_id || info.seen_message_id || 0;
return lastFetchedID >= message.getID();
});
var fetchedPartnerIDs = _.map(fetchedPartnersInfo, function (info) {
@@ -85,7 +85,7 @@ var ChannelSeenMixin = {
return info.partner_id !== session.partner_id;
});
var seenMessageIDs = _.map(otherPartnersInfo, function (info) {
return info.last_seen_message_id || 0;
return info.seen_message_id || 0;
});
if (_.isEmpty(seenMessageIDs)) {
return 0;
@@ -106,7 +106,7 @@ var ChannelSeenMixin = {
// seen partner IDs
var seenPartnersInfo = _.filter(otherPartnersInfo, function (info) {
return info.last_seen_message_id >= message.getID();
return info.seen_message_id >= message.getID();
});
var seenPartnerIDs = _.map(seenPartnersInfo, function (info) {
return info.partner_id;
@@ -128,7 +128,7 @@ var ChannelSeenMixin = {
return info.partner_id !== session.partner_id;
});
var lastFetchedMessageIDs = _.map(otherPartnersInfo, function (info) {
return info.last_fetched_message_id || info.last_seen_message_id || 0;
return info.fetched_message_id || info.seen_message_id || 0;
});
if (_.isEmpty(lastFetchedMessageIDs)) {
return 0;
@@ -144,7 +144,7 @@ var ChannelSeenMixin = {
return info.partner_id !== session.partner_id;
});
var lastSeenMessageIDs = _.map(otherPartnersInfo, function (info) {
return info.last_seen_message_id || 0;
return info.seen_message_id || 0;
});
if (_.isEmpty(lastSeenMessageIDs)) {
return 0;
@@ -160,7 +160,7 @@ var ChannelSeenMixin = {
return info.partner_id !== session.partner_id;
});
var lastFetchedMessageIDs = _.map(otherPartnersInfo, function (info) {
return info.last_fetched_message_id || info.last_seen_message_id || 0;
return info.fetched_message_id || info.seen_message_id || 0;
});
if (_.isEmpty(lastFetchedMessageIDs)) {
return false;
@@ -179,7 +179,7 @@ var ChannelSeenMixin = {
return info.partner_id !== session.partner_id;
});
var lastSeenMessageIDs = _.map(otherPartnersInfo, function (info) {
return info.last_seen_message_id || 0;
return info.seen_message_id || 0;
});
if (_.isEmpty(lastSeenMessageIDs)) {
return false;
@@ -206,16 +206,16 @@ var ChannelSeenMixin = {
if (!seenInfo) {
seenInfo = {
partner_id: data.partner_id,
last_seen_message_id: 0,
last_fetched_message_id: 0,
seen_message_id: 0,
fetched_message_id: 0,
};
this._seenPartnersInfo.push(seenInfo);
}
if (data.info === 'channel_fetched') {
seenInfo.last_fetched_message_id = data.last_message_id;
seenInfo.fetched_message_id = data.last_message_id;
} else if (data.info === 'channel_seen') {
seenInfo.last_fetched_message_id = data.last_message_id;
seenInfo.last_seen_message_id = data.last_message_id;
seenInfo.fetched_message_id = data.last_message_id;
seenInfo.seen_message_id = data.last_message_id;
}
this.call('mail_service', 'getMailBus').trigger('update_channel', this.getID());
},
Oops, something went wrong.

0 comments on commit 38c1f79

Please sign in to comment.