[FIX] mail: fix is_typing timeout after closing the channel

This PR fixes an error that occured when a typing timeout callback was called
after closing the channel.

Steps to reproduce the issue:
- Open a channel in the Discuss app.
- Type some text in the composer.
- Close the channel.
- Wait 5 seconds.
- The following traceback appears.

```
UncaughtPromiseError > TypeError
Uncaught Promise > undefined is not iterable (cannot read property Symbol(Symbol.iterator))
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at ModelField._convertX2ManyValue (http://localhost:8069/web/assets/debug/web.assets_backend.js:130149:28) (/mail/static/src/model/model_field.js:499)
    at ModelField._setRelationUnlinkX2Many (http://localhost:8069/web/assets/debug/web.assets_backend.js:130445:38) (/mail/static/src/model/model_field.js:795)
    at ModelField._setRelationUnlink (http://localhost:8069/web/assets/debug/web.assets_backend.js:130425:29) (/mail/static/src/model/model_field.js:775)
    at ModelField.parseAndExecuteCommands (http://localhost:8069/web/assets/debug/web.assets_backend.js:130086:34) (/mail/static/src/model/model_field.js:436)
    at ModelManager._update (http://localhost:8069/web/assets/debug/web.assets_backend.js:132561:24) (/mail/static/src/model/model_manager.js:1304)
    at ModelManager.update (http://localhost:8069/web/assets/debug/web.assets_backend.js:131589:26) (/mail/static/src/model/model_manager.js:332)
    at model.update (http://localhost:8069/web/assets/debug/web.assets_backend.js:133012:31) (/mail/static/src/core_models/record.js:139)
    at model.unregisterCurrentPartnerIsTyping (http://localhost:8069/web/assets/debug/web.assets_backend.js:157479:18) (/mail/static/src/models/thread.js:941)
    at model.onCurrentPartnerInactiveTypingTimeout (http://localhost:8069/web/assets/debug/web.assets_backend.js:157593:18) (/mail/static/src/models/thread.js:1055)
    at model.onTimeout (http://localhost:8069/web/assets/debug/web.assets_backend.js:160569:69) (/mail/static/src/models/timer.js:34)
```

closes odoo/odoo#113424

X-original-commit: 3a586c2a20de2a8208f7b3d55086bf86dda92577
Signed-off-by: Stockbauer Matthieu (tsm) <tsm@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
tsm-odoo
2023-02-22 21:37:30 +01:00
parent edb58695b4
commit 36aa579ed8
4 changed files with 44 additions and 1 deletions
+1 -1
View File
@@ -1010,7 +1010,7 @@ Model({
this.update({
isCurrentPartnerTyping: false,
orderedTypingMembers: newOrderedTypingMembers,
typingMembers: unlink(memberOfCurrentUser),
typingMembers: memberOfCurrentUser ? unlink(memberOfCurrentUser) : undefined,
});
// Notify typing status to other members.
if (immediateNotify) {
@@ -180,6 +180,9 @@ patch(MockServer.prototype, "mail/controllers/discuss", {
["channel_id", "=", channel_id],
["partner_id", "=", partnerId],
]);
if (!memberOfCurrentUser) {
return;
}
this._mockMailChannelMember_NotifyTyping([memberOfCurrentUser.id], is_typing);
},
/**
@@ -404,6 +404,7 @@ export {
afterNextRender,
dragenterFiles,
dropFiles,
insertText,
isScrolledToBottom,
nextAnimationFrame,
nextTick,
@@ -4,6 +4,7 @@ import {
afterNextRender,
dragenterFiles,
dropFiles,
insertText,
nextAnimationFrame,
pasteFiles,
start,
@@ -1729,4 +1730,42 @@ QUnit.module("mail", {}, function () {
}
);
});
QUnit.test(
"No error when typing timeout occurs after closing the channel",
async function (assert) {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({
im_status: "online",
name: "Demo",
});
const channelId = pyEnv["mail.channel"].create({
name: "Gryffindor",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
});
const { advanceTime, click, messaging, openDiscuss } = await start({
hasTimeControl: true,
discuss: {
context: {
active_id: channelId,
},
},
});
await openDiscuss();
await afterNextRender(() => insertText(".o_ComposerTextInputView_textarea", "Hello"));
await click(".o_DiscussSidebarCategoryItem_commandLeave");
const thread = messaging.models["Thread"].findFromIdentifyingData({
id: channelId,
model: "mail.channel",
});
const { duration } = messaging.models["Timer"].findFromIdentifyingData({
threadAsCurrentPartnerInactiveTypingTimerOwner: thread,
});
await advanceTime(duration);
assert.containsNone(document.body, ".o_DiscussSidebarCategoryItem");
}
);
});