From 2cd3484de93336acd3be27a3284c1ddaa1323b8a Mon Sep 17 00:00:00 2001 From: Ipsita Borisagar Date: Mon, 17 Jan 2022 04:56:21 +0000 Subject: [PATCH] [FIX] mail, test_discuss_full: add guests name into group dm name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: In discuss, the group DM default name does not contain any guest names in it. After this commit: Group DM default name will also take guest names along with other user names. Task-2664859 closes odoo/odoo#86130 X-original-commit: 41f4c5741097b09c372406bbbd5364314bff6d1b Signed-off-by: Sébastien Theys (seb) --- addons/mail/i18n/mail.pot | 7 ++++ addons/mail/models/mail_channel.py | 4 +++ .../mail/static/src/models/thread/thread.js | 34 +++++++++++++++++-- .../tests/test_performance.py | 7 ++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/addons/mail/i18n/mail.pot b/addons/mail/i18n/mail.pot index a6c95b3ca6e..a7ff7e5061a 100644 --- a/addons/mail/i18n/mail.pot +++ b/addons/mail/i18n/mail.pot @@ -193,6 +193,13 @@ msgstr "" msgid "(originally assigned to" msgstr "" +#. module: mail +#. openerp-web +#: code:addons/mail/static/src/models/thread/thread.js:0 +#, python-format +msgid ", " +msgstr "" + #. module: mail #. openerp-web #: code:addons/mail/static/src/components/composer/composer.xml:0 diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 7b9ddef41cc..07bd82af11f 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -794,6 +794,10 @@ class Channel(models.Model): 'fetched_message_id': cp.fetched_message_id.id, 'seen_message_id': cp.seen_message_id.id, } for cp in members_by_channel[channel] if cp.partner_id], key=lambda p: p['partner_id']) + info['guestMembers'] = [('insert', sorted([{ + 'id': member.guest_id.id, + 'name': member.guest_id.name, + } for member in members_by_channel[channel] if member.guest_id], key=lambda g: g['id']))] # add RTC sessions info info.update({ diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index bf66eccb074..4f8565a6577 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -164,6 +164,9 @@ registerModel({ if ('group_based_subscription' in data) { data2.group_based_subscription = data.group_based_subscription; } + if ('guestMembers' in data) { + data2.guestMembers = data.guestMembers; + } if ('id' in data) { data2.id = data.id; } @@ -1231,8 +1234,10 @@ registerModel({ if (this.channel_type === 'chat' && this.correspondent) { return this.custom_channel_name || this.correspondent.nameOrDisplayName; } - if (this.channel_type === 'group') { - return this.name || this.members.map(partner => partner.nameOrDisplayName).join(', '); + if (this.channel_type === 'group' && !this.name) { + const partnerNames = this.members.map(partner => partner.nameOrDisplayName); + const guestNames = this.guestMembers.map(guest => guest.name); + return [...partnerNames, ...guestNames].join(this.env._t(", ")); } return this.name; }, @@ -1781,6 +1786,26 @@ registerModel({ }, }); }, + /** + * @private + * @returns {Array[]} + */ + _sortGuestMembers() { + return [ + ['defined-first', 'name'], + ['case-insensitive-asc', 'name'], + ]; + }, + /** + * @private + * @returns {Array[]} + */ + _sortPartnerMembers() { + return [ + ['defined-first', 'nameOrDisplayName'], + ['case-insensitive-asc', 'nameOrDisplayName'], + ]; + }, /** * @private * @param {Partner[]} members @@ -1949,7 +1974,9 @@ registerModel({ group_based_subscription: attr({ default: false, }), - guestMembers: many('Guest'), + guestMembers: many('Guest', { + sort: '_sortGuestMembers', + }), /** * States whether `this` has activities (`mail.activity.mixin` server side). */ @@ -2119,6 +2146,7 @@ registerModel({ memberCount: attr(), members: many('Partner', { inverse: 'memberThreads', + sort: '_sortPartnerMembers', }), /** * Determines the last mentioned channels of the last composer related diff --git a/addons/test_discuss_full/tests/test_performance.py b/addons/test_discuss_full/tests/test_performance.py index 7c45e1b9681..6bd8230774c 100644 --- a/addons/test_discuss_full/tests/test_performance.py +++ b/addons/test_discuss_full/tests/test_performance.py @@ -289,6 +289,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_group_1.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -352,6 +353,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_chat_1.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -415,6 +417,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_chat_2.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -478,6 +481,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_chat_3.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -541,6 +545,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_chat_4.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -604,6 +609,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_livechat_1.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])], @@ -667,6 +673,7 @@ class TestDiscussFullPerformance(TransactionCase): 'defaultDisplayMode': False, 'description': False, 'group_based_subscription': False, + 'guestMembers': [('insert', [])], 'id': channel_livechat_2.id, 'invitedGuests': [('insert', [])], 'invitedPartners': [('insert', [])],