From 36aa579ed8c90e10c600edde03f172fdfc512f90 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Wed, 22 Feb 2023 08:55:56 +0000 Subject: [PATCH] [FIX] mail: fix is_typing timeout after closing the channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/models/thread.js | 2 +- .../mock_server/controllers/discuss.js | 3 ++ .../mail/static/tests/helpers/test_utils.js | 1 + .../components/composer_tests.js | 39 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index 4d550b504a2..657f643749a 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -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) { diff --git a/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js b/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js index 364d296da3c..7b94b9f2b46 100644 --- a/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js +++ b/addons/mail/static/tests/helpers/mock_server/controllers/discuss.js @@ -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); }, /** diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index ec3b84ae202..6fc242924f2 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -404,6 +404,7 @@ export { afterNextRender, dragenterFiles, dropFiles, + insertText, isScrolledToBottom, nextAnimationFrame, nextTick, diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js index 5dd155b7441..467461063b3 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js @@ -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"); + } + ); });