[FIX] mail: (mobile) Prevent server sync for open/close state
This commit prevents the opening/closure of a channel on mobile when the action is performed on desktop and reciprocally closes odoo/odoo#66102 Tasks-id: 2267593 X-original-commit: a257e0ede12ead06c0f8dba90c3868761da6ea71 Related: odoo/enterprise#16323 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -665,6 +665,121 @@ QUnit.test('chat window: open / close', async function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('Mobile: opening a chat window should not update channel state on the server', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data['mail.channel'].records.push({
|
||||
id: 20,
|
||||
state: 'closed',
|
||||
});
|
||||
await this.start({
|
||||
env: {
|
||||
device: {
|
||||
isMobile: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click());
|
||||
await afterNextRender(() => document.querySelector(`.o_NotificationList_preview`).click());
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_ChatWindow',
|
||||
"should have a chat window after clicking on thread preview"
|
||||
);
|
||||
const channels = await this.env.services.rpc({
|
||||
model: 'mail.channel',
|
||||
method: 'read',
|
||||
args: [20],
|
||||
}, { shadow: true });
|
||||
assert.strictEqual(
|
||||
channels[0].state,
|
||||
'closed',
|
||||
'opening a chat window in mobile should not update channel state on the server',
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('Mobile: closing a chat window should not update channel state on the server', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data['mail.channel'].records.push({
|
||||
id: 20,
|
||||
state: 'open',
|
||||
});
|
||||
await this.start({
|
||||
env: {
|
||||
device: {
|
||||
isMobile: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
await afterNextRender(() => document.querySelector(`.o_MessagingMenu_toggler`).click());
|
||||
await afterNextRender(() => document.querySelector(`.o_NotificationList_preview`).click());
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_ChatWindow',
|
||||
"should have a chat window after clicking on thread preview"
|
||||
);
|
||||
// Close chat window
|
||||
await afterNextRender(() => document.querySelector(`.o_ChatWindowHeader_commandClose`).click());
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_ChatWindow',
|
||||
"should not have a chat window after closing it"
|
||||
);
|
||||
const channels = await this.env.services.rpc({
|
||||
model: 'mail.channel',
|
||||
method: 'read',
|
||||
args: [20],
|
||||
}, { shadow: true });
|
||||
assert.strictEqual(
|
||||
channels[0].state,
|
||||
'open',
|
||||
'closing the chat window should not update channel state on the server',
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Mobile: chat window shouldn't open automatically after receiving a new message", async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
this.data['res.partner'].records.push({ id: 10, name: "Demo" });
|
||||
this.data['res.users'].records.push({
|
||||
id: 42,
|
||||
partner_id: 10,
|
||||
});
|
||||
this.data['mail.channel'].records = [
|
||||
{
|
||||
channel_type: "chat",
|
||||
id: 10,
|
||||
members: [this.data.currentPartnerId, 10],
|
||||
uuid: 'channel-10-uuid',
|
||||
},
|
||||
];
|
||||
await this.start({
|
||||
env: {
|
||||
device: {
|
||||
isMobile: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// simulate receiving a message
|
||||
await afterNextRender(() => this.env.services.rpc({
|
||||
route: '/mail/chat_post',
|
||||
params: {
|
||||
context: {
|
||||
mockedUserId: 42,
|
||||
},
|
||||
message_content: "hu",
|
||||
uuid: 'channel-10-uuid',
|
||||
},
|
||||
}));
|
||||
assert.containsNone(
|
||||
document.body,
|
||||
'.o_ChatWindow',
|
||||
"On mobile, the chat window shouldn't open automatically after receiving a new message"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('chat window: close on ESCAPE', async function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
|
||||
@@ -39,9 +39,12 @@ function factory(dependencies) {
|
||||
* Close this chat window.
|
||||
*
|
||||
* @param {Object} [param0={}]
|
||||
* @param {boolean} [param0.notifyServer=true]
|
||||
* @param {boolean} [param0.notifyServer]
|
||||
*/
|
||||
close({ notifyServer = true } = {}) {
|
||||
close({ notifyServer } = {}) {
|
||||
if (notifyServer === undefined) {
|
||||
notifyServer = !this.env.messaging.device.isMobile;
|
||||
}
|
||||
const thread = this.thread;
|
||||
this.delete();
|
||||
// Flux specific: 'closed' fold state should only be saved on the
|
||||
@@ -89,9 +92,12 @@ function factory(dependencies) {
|
||||
|
||||
/**
|
||||
* @param {Object} [param0={}]
|
||||
* @param {boolean} [param0.notifyServer=true]
|
||||
* @param {boolean} [param0.notifyServer]
|
||||
*/
|
||||
fold({ notifyServer = true } = {}) {
|
||||
fold({ notifyServer } = {}) {
|
||||
if (notifyServer === undefined) {
|
||||
notifyServer = !this.env.messaging.device.isMobile;
|
||||
}
|
||||
this.update({ isFolded: true });
|
||||
// Flux specific: manually folding the chat window should save the
|
||||
// new state on the server.
|
||||
@@ -140,9 +146,12 @@ function factory(dependencies) {
|
||||
|
||||
/**
|
||||
* @param {Object} [param0={}]
|
||||
* @param {boolean} [param0.notifyServer=true]
|
||||
* @param {boolean} [param0.notifyServer]
|
||||
*/
|
||||
unfold({ notifyServer = true } = {}) {
|
||||
unfold({ notifyServer } = {}) {
|
||||
if (notifyServer === undefined) {
|
||||
notifyServer = !this.env.messaging.device.isMobile;
|
||||
}
|
||||
this.update({ isFolded: false });
|
||||
// Flux specific: manually opening the chat window should save the
|
||||
// new state on the server.
|
||||
|
||||
@@ -103,15 +103,18 @@ function factory(dependencies) {
|
||||
* @param {Object} [param1={}]
|
||||
* @param {boolean} [param1.isFolded=false]
|
||||
* @param {boolean} [param1.makeActive=false]
|
||||
* @param {boolean} [param1.notifyServer=true]
|
||||
* @param {boolean} [param1.notifyServer]
|
||||
* @param {boolean} [param1.replaceNewMessage=false]
|
||||
*/
|
||||
openThread(thread, {
|
||||
isFolded = false,
|
||||
makeActive = false,
|
||||
notifyServer = true,
|
||||
notifyServer,
|
||||
replaceNewMessage = false
|
||||
} = {}) {
|
||||
if (notifyServer === undefined) {
|
||||
notifyServer = !this.env.messaging.device.isMobile;
|
||||
}
|
||||
let chatWindow = this.chatWindows.find(chatWindow =>
|
||||
chatWindow.thread === thread
|
||||
);
|
||||
|
||||
+2
-2
@@ -263,7 +263,7 @@ function factory(dependencies) {
|
||||
channel.markAsFetched();
|
||||
}
|
||||
// (re)open chat on receiving new message
|
||||
if (channel.channel_type !== 'channel') {
|
||||
if (channel.channel_type !== 'channel' && !this.env.messaging.device.isMobile) {
|
||||
this.env.messaging.chatWindowManager.openThread(channel);
|
||||
}
|
||||
}
|
||||
@@ -697,7 +697,7 @@ function factory(dependencies) {
|
||||
const chat = await this.async(() =>
|
||||
this.env.messaging.getChat({ partnerId: partner_id }
|
||||
));
|
||||
if (!chat) {
|
||||
if (!chat || this.env.messaging.device.isMobile) {
|
||||
return;
|
||||
}
|
||||
this.env.messaging.chatWindowManager.openThread(chat);
|
||||
|
||||
@@ -1510,6 +1510,9 @@ function factory(dependencies) {
|
||||
// avoid crash during destroy
|
||||
return;
|
||||
}
|
||||
if (this.env.messaging.device.isMobile) {
|
||||
return;
|
||||
}
|
||||
if (this.serverFoldState === 'closed') {
|
||||
this.env.messaging.chatWindowManager.closeThread(this, {
|
||||
notifyServer: false,
|
||||
|
||||
Reference in New Issue
Block a user