From 885ae723d7ff58a273d97b5dfe9912ff5c02aa42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 6 Mar 2024 17:13:34 +0100 Subject: [PATCH] [FIX] im_livechat: mention partner in full composer should not crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Making a mention in full composer when `im_livechat` is installed was making the following crash: ``` TypeError: Cannot read properties of undefined (reading 'type') at SuggestionService.fetchSuggestions ``` Steps to reproduce: - install module `im_livechat` - open contacts app form view - open full composer (e.g. Log note => expand icon) - type @ + a character => throws error above This happens because `SuggestionService` methods can optionally pass a thread, but livechat overrides wrongfully assume they were always provided. This commit fixes the issue with optional chaining, taking into account it's optional. No test because full composer doesn't work in unit tests, tours require adding steps blindly and I've already wasted too much time to no avail. closes odoo/odoo#156773 Signed-off-by: Sébastien Theys (seb) --- .../static/src/core/web/suggestion_service_patch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/im_livechat/static/src/core/web/suggestion_service_patch.js b/addons/im_livechat/static/src/core/web/suggestion_service_patch.js index 9cfd68bdf9a..b86eb2926ec 100644 --- a/addons/im_livechat/static/src/core/web/suggestion_service_patch.js +++ b/addons/im_livechat/static/src/core/web/suggestion_service_patch.js @@ -12,7 +12,7 @@ patch(SuggestionService.prototype, { : super.getSupportedDelimiters(...arguments); }, async fetchSuggestions({ delimiter, term }, { thread } = {}) { - if (thread.type === "livechat" && delimiter === "#") { + if (thread?.type === "livechat" && delimiter === "#") { return; } return super.fetchSuggestions(...arguments); @@ -30,7 +30,7 @@ patch(SuggestionService.prototype, { * @returns {[mainSuggestion[], extraSuggestion[]]} */ searchSuggestions({ delimiter, term }, { thread } = {}, sort = false) { - if (thread.type === "livechat" && delimiter === "#") { + if (thread?.type === "livechat" && delimiter === "#") { return { type: undefined, mainSuggestions: [],