summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-12-05 14:34:56 +0000
committerAlexandre Kühn <aku@odoo.com>2018-12-06 14:51:28 +0000
commit9117d968e056d7c4e1112079e7e0ea0dd63cf9a5 (patch)
tree5576d8d25369d0249f0d22eaeaa7bc26a1ed6d57
parentae5d22fa0766360a43752d6d25dd0c4260dac34f (diff)
[FIX] mail: get members on channel_info
Before this commit, when accessing a channel after a page reload, the list of members in a channel was not known until the composer on this channel has the focus, either in the Discuss app or in a chat window. This was a good-enough condition when information about members was limited to mention suggestions, which requires having the focus on the composer. However, with the 'is typing' features on channels, it requires being aware of the members of the channel at the moment of the rendering in discuss or in a chat window. This commit fixes the issue by providing the list of channel members when retrieving information about the channel. Without this fix, the 'is typing' notifications could sometimes not determine the name(s) and email(s) of user(s) typing something.
-rw-r--r--addons/mail/models/mail_channel.py38
-rw-r--r--addons/mail/static/src/js/models/threads/channel.js6
2 files changed, 31 insertions, 13 deletions
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index 2b060cf1276..778ee09d4c4 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -537,10 +537,13 @@ class Channel(models.Model):
:rtype : list(dict)
"""
channel_infos = []
- 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:
- 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 = {
@@ -573,17 +576,28 @@ class Channel(models.Model):
if last_message:
info['last_message'] = last_message[0].get('last_message')
- # add user session state, if available and if user is logged
- if partner_channels.ids:
- partner_channel = partner_channels.filtered(lambda c: channel.id == c.channel_id.id)
- 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['seen_message_id'] = partner_channel.seen_message_id.id
+ # 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 len(partner_channel.ids):
+ partner_channel = partner_channel[0]
+ info['state'] = partner_channel.fold_state or 'open'
+ info['is_minimized'] = partner_channel.is_minimized
+ info['seen_message_id'] = partner_channel.seen_message_id.id
+
+ # 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]
+
channel_infos.append(info)
return channel_infos
diff --git a/addons/mail/static/src/js/models/threads/channel.js b/addons/mail/static/src/js/models/threads/channel.js
index ff90ca8edfb..f6839873ef7 100644
--- a/addons/mail/static/src/js/models/threads/channel.js
+++ b/addons/mail/static/src/js/models/threads/channel.js
@@ -29,6 +29,10 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, {
* @param {boolean} params.data.is_moderator whether the current user is
* moderator of this channel.
* @param {string} [params.data.last_message_date] date in server-format
+ * @param {Object[]} [params.data.members=[]]
+ * @param {integer} [params.data.members[i].id]
+ * @param {string} [params.data.members[i].name]
+ * @param {string} [params.data.members[i].email]
* @param {integer} [params.data.message_unread_counter]
* @param {boolean} [params.data.moderation=false] whether the channel is
* moderated or not
@@ -61,7 +65,7 @@ var Channel = SearchableThread.extend(ThreadTypingMixin, {
this._isModerated = data.moderation;
this._isMyselfModerator = data.is_moderator;
this._lastMessageDate = undefined;
- this._members = [];
+ this._members = data.members || [];
// Deferred that is resolved on fetched members of this channel.
this._membersDef = undefined;
// number of messages that are 'needaction', which is equivalent to the