diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-10-27 15:18:57 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-10-27 15:18:57 +0000 |
| commit | 063aa1deccdd6b53d1ab7de68921c95ecf60581c (patch) | |
| tree | 51b65c2c75706e02fd27a242836862e7f372ec3e /addons/mail/static/src/models | |
| parent | 4e660dfdf40a36eed7123bcea2452874238fddd8 (diff) | |
[FIX] mail, im_livechat: allow to reopen closed chat in discuss
task-2346862
closes odoo/odoo#60080
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
4 files changed, 92 insertions, 48 deletions
diff --git a/addons/mail/static/src/models/messaging_initializer/messaging_initializer.js b/addons/mail/static/src/models/messaging_initializer/messaging_initializer.js index 13da76dbb38..da2f51757be 100644 --- a/addons/mail/static/src/models/messaging_initializer/messaging_initializer.js +++ b/addons/mail/static/src/models/messaging_initializer/messaging_initializer.js @@ -169,7 +169,7 @@ function factory(dependencies) { // flux specific: channels received at init have to be // considered pinned. task-2284357 if (!channel.isPinned) { - channel.update({ isPendingPinned: true }); + channel.pin(); } } } diff --git a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js index 783b43e4f20..affa3c05a30 100644 --- a/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler/messaging_notification_handler.js @@ -205,7 +205,7 @@ function factory(dependencies) { ))[0]; } if (!channel.isPinned) { - channel.update({ isPendingPinned: true }); + channel.pin(); } const message = this.env.models['mail.message'].insert(convertedData); diff --git a/addons/mail/static/src/models/thread/thread.js b/addons/mail/static/src/models/thread/thread.js index cd1ee77b1ce..4de44f8b3ec 100644 --- a/addons/mail/static/src/models/thread/thread.js +++ b/addons/mail/static/src/models/thread/thread.js @@ -341,7 +341,6 @@ function factory(dependencies) { return channels; } - /** * Performs the `channel_seen` RPC on `mail.channel`. * @@ -362,6 +361,25 @@ function factory(dependencies) { } /** + * Performs the `channel_pin` RPC on `mail.channel`. + * + * @static + * @param {Object} param0 + * @param {boolean} [param0.pinned=false] + * @param {string} param0.uuid + */ + static async performRpcChannelPin({ pinned = false, uuid }) { + return this.env.services.rpc({ + model: 'mail.channel', + method: 'channel_pin', + kwargs: { + uuid, + pinned, + }, + }, { shadow: true }); + } + + /** * Performs the `channel_create` RPC on `mail.channel`. * * @static @@ -453,6 +471,25 @@ function factory(dependencies) { } /** + * Performs the `execute_command` RPC on `mail.channel`. + * + * @static + * @param {Object} param0 + * @param {string} param0.command the command to execute + * @param {integer[]} param0.ids list of id of channels + */ + static async performRpcExecuteCommand({ command, ids }) { + return this.env.services.rpc({ + model: 'mail.channel', + method: 'execute_command', + args: [ids], + kwargs: { + command, + } + }); + } + + /** * Performs RPC on the route `/mail/get_suggested_recipients`. * * @static @@ -633,23 +670,17 @@ function factory(dependencies) { * * Only makes sense if isPendingPinned is set to the desired value. */ - notifyPinStateToServer() { - // method is called from _updateAfter so it cannot be async + async notifyPinStateToServer() { if (this.isPendingPinned) { - this.env.services.rpc({ - model: 'mail.channel', - method: 'channel_pin', - kwargs: { - uuid: this.uuid, - pinned: true, - }, - }, { shadow: true }); + await this.env.models['mail.thread'].performRpcChannelPin({ + pinned: true, + uuid: this.uuid, + }); } else { - this.env.services.rpc({ - model: 'mail.channel', - method: 'execute_command', - args: [[this.id], 'leave'] - }, { shadow: true }); + await this.env.models['mail.thread'].performRpcExecuteCommand({ + command: 'leave', + ids: [this.id], + }); } } @@ -701,6 +732,14 @@ function factory(dependencies) { } /** + * Pin this thread and notify server of the change. + */ + async pin() { + this.update({ isPendingPinned: true }); + await this.notifyPinStateToServer(); + } + + /** * Open a dialog to add channels as followers. */ promptAddChannelFollower() { @@ -868,6 +907,14 @@ function factory(dependencies) { } /** + * Unpin this thread and notify server of the change. + */ + async unpin() { + this.update({ isPendingPinned: false }); + await this.notifyPinStateToServer(); + } + + /** * Called when current partner has explicitly stopped inserting some * input in composer. Useful to notify current partner has currently * stopped typing something in the composer of this thread to all other @@ -921,7 +968,7 @@ function factory(dependencies) { */ unsubscribe() { this.env.messaging.chatWindowManager.closeThread(this); - this.update({ isPendingPinned: false }); + this.unpin(); } //---------------------------------------------------------------------- @@ -1297,6 +1344,19 @@ function factory(dependencies) { } /** + * Handles change of pinned state coming from the server. Useful to + * clear pending state once server acknowledged the change. + * + * @private + * @see isPendingPinned + */ + _onIsServerPinnedChanged() { + if (this.isServerPinned === this.isPendingPinned) { + this.update({ isPendingPinned: clear() }); + } + } + + /** * Handles change of fold state coming from the server. Useful to * synchronize corresponding chat window. * @@ -1350,34 +1410,6 @@ function factory(dependencies) { }); } - /** - * @override - */ - _updateAfter(previous) { - if (this.model !== 'mail.channel') { - // pin state only makes sense on channels - return; - } - if ( - this.isPendingPinned !== undefined && - previous.isPendingPinned !== this.isPendingPinned - ) { - this.notifyPinStateToServer(); - } - if (this.isServerPinned === this.isPendingPinned) { - this.update({ isPendingPinned: clear() }); - } - } - - /** - * @override - */ - _updateBefore() { - return { - isPendingPinned: this.isPendingPinned, - }; - } - //---------------------------------------------------------------------- // Handlers //---------------------------------------------------------------------- @@ -1702,6 +1734,16 @@ function factory(dependencies) { dependencies: ['messages'], }), /** + * Not a real field, used to trigger `_onIsServerPinnedChanged` when one of + * the dependencies changes. + */ + onIsServerPinnedChanged: attr({ + compute: '_onIsServerPinnedChanged', + dependencies: [ + 'isServerPinned', + ], + }), + /** * Not a real field, used to trigger `_onServerFoldStateChanged` when one of * the dependencies changes. */ diff --git a/addons/mail/static/src/models/user/user.js b/addons/mail/static/src/models/user/user.js index 2decc8efd92..172b8c5b780 100644 --- a/addons/mail/static/src/models/user/user.js +++ b/addons/mail/static/src/models/user/user.js @@ -113,7 +113,9 @@ function factory(dependencies) { thread.model === 'mail.channel' && thread.public === 'private' ); - if (!chat) { + if (!chat ||!chat.isPinned) { + // if chat is not pinned then it has to be pinned client-side + // and server-side, which is a side effect of following rpc chat = await this.async(() => this.env.models['mail.thread'].performRpcCreateChat({ partnerIds: [this.partner.id], |
