[FIX] im_livechat: mention partner in full composer should not crash

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) <seb@odoo.com>
This commit is contained in:
Alexandre Kühn
2024-03-06 17:48:16 +00:00
parent 139baee01f
commit 885ae723d7
@@ -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: [],