diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 1a300b70b8a..46b419a0ab3 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -936,14 +936,13 @@ class Channel(models.Model): channel._broadcast(partners_to) return channel.channel_info()[0] - @api.model - def channel_fold(self, uuid, state=None): + def channel_fold(self, state=None): """ Update the fold_state of the given session. In order to syncronize web browser tabs, the change will be broadcast to himself (the current user channel). Note: the user need to be logged :param state : the new status of the session for the current user. """ - domain = [('partner_id', '=', self.env.user.partner_id.id), ('channel_id.uuid', '=', uuid)] + domain = [('partner_id', '=', self.env.user.partner_id.id), ('channel_id', 'in', self.ids)] for session_state in self.env['mail.channel.partner'].search(domain): if not state: state = session_state.fold_state @@ -960,7 +959,7 @@ class Channel(models.Model): if vals: session_state.write(vals) self.env['bus.bus']._sendone(self.env.user.partner_id, 'mail.channel/insert', { - 'id': session_state.channel_id.channel_info()[0]['id'], + 'id': session_state.channel_id.id, 'serverFoldState': state, }) diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index 4f7f1a95d2b..5c3645772dd 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -388,16 +388,16 @@ registerModel({ /** * Performs the `channel_fold` RPC on `mail.channel`. * - * @param {string} uuid + * @param {number} channelId * @param {string} state */ - async performRpcChannelFold(uuid, state) { + async performRpcChannelFold(channelId, state) { return this.env.services.rpc({ model: 'mail.channel', method: 'channel_fold', + args: [[channelId]], kwargs: { state, - uuid, } }, { shadow: true }); }, @@ -875,10 +875,7 @@ registerModel({ // Server sync of fold state is only supported for channels. return; } - if (!this.uuid) { - return; - } - return this.messaging.models['Thread'].performRpcChannelFold(this.uuid, state); + return this.messaging.models['Thread'].performRpcChannelFold(this.id, state); }, /** * Notify server to leave the current channel. Useful for cross-tab diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index a0cbe934417..964ddd5f207 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -171,9 +171,9 @@ MockServer.include({ return this._mockMailChannelChannelFetchPreview(ids); } if (args.model === 'mail.channel' && args.method === 'channel_fold') { - const uuid = args.args[0] || args.kwargs.uuid; + const ids = args.args[0]; const state = args.args[1] || args.kwargs.state; - return this._mockMailChannelChannelFold(uuid, state); + return this._mockMailChannelChannelFold(ids, state); } if (args.model === 'mail.channel' && args.method === 'channel_get') { const partners_to = args.args[0] || args.kwargs.partners_to; @@ -871,25 +871,27 @@ MockServer.include({ * In particular sends a notification on the bus. * * @private - * @param {string} uuid + * @param {number} ids * @param {state} [state] */ - _mockMailChannelChannelFold(uuid, state) { - const channel = this._getRecords('mail.channel', [['uuid', '=', uuid]])[0]; - const [memberOfCurrentUser] = this._getRecords('mail.channel.partner', [['channel_id', '=', channel.id], ['partner_id', '=', this.currentPartnerId]]); - const foldState = state ? state : memberOfCurrentUser.fold_state === 'open' ? 'folded' : 'open'; - const vals = { - fold_state: foldState, - is_minimized: foldState !== 'closed', - }; - this._mockWrite('mail.channel.partner', [[memberOfCurrentUser.id], vals]); - this._widget.call('bus_service', 'trigger', 'notification', [{ - type: 'mail.channel/insert', - payload: { - id: channel.id, - serverFoldState: memberOfCurrentUser.fold_state, - }, - }]); + _mockMailChannelChannelFold(ids, state) { + const channels = this._getRecords('mail.channel', [['id', 'in', ids]]); + for (const channel of channels) { + const [memberOfCurrentUser] = this._getRecords('mail.channel.partner', [['channel_id', '=', channel.id], ['partner_id', '=', this.currentPartnerId]]); + const foldState = state ? state : memberOfCurrentUser.fold_state === 'open' ? 'folded' : 'open'; + const vals = { + fold_state: foldState, + is_minimized: foldState !== 'closed', + }; + this._mockWrite('mail.channel.partner', [[memberOfCurrentUser.id], vals]); + this._widget.call('bus_service', 'trigger', 'notification', [{ + type: 'mail.channel/insert', + payload: { + id: channel.id, + serverFoldState: memberOfCurrentUser.fold_state, + }, + }]); + } }, /** * Simulates 'channel_get' on 'mail.channel'. diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js index 5c9784e6a00..462333a46b2 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chat_window_manager_tests.js @@ -520,7 +520,7 @@ QUnit.test('chat window: fold', async function (assert) { assert.expect(9); const pyEnv = await startServer(); - pyEnv['mail.channel'].create({ uuid: 'channel-uuid' }); + pyEnv['mail.channel'].create({}); const { click, createMessagingMenuComponent } = await this.start({ mockRPC(route, args) { if (args.method === 'channel_fold') { @@ -572,7 +572,7 @@ QUnit.test('chat window: open / close', async function (assert) { assert.expect(10); const pyEnv = await startServer(); - pyEnv['mail.channel'].create({ uuid: 'channel-uuid' }); + pyEnv['mail.channel'].create({}); const { click, createMessagingMenuComponent } = await this.start({ mockRPC(route, args) { if (args.method === 'channel_fold') {