[FIX] mail: no crash when closing chat window from barcode app

Steps to reproduce:
- Open barcodde app
- Go to Operations > Delivery Orders
- Click on avatar button to open chat
- Click on back button

Traceback:
```
Cannot read properties of null (reading 'click')
```

This happens because closing the chat window attempts to
open the messaging menu in mobile. This assumes chat
windows are working in `/web` and the systray is available.
Barcode app is special because it's in `/web` but the systray
is not available.

This commit fixes the issue by opening the messaging menu if it
can, otherwise it silently does nothing.

Task-3439660

closes odoo/odoo#129858

X-original-commit: 399f191dc1bb40d352890607413fa72462f1a99d
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit is contained in:
Alexandre Kühn
2023-07-27 13:25:12 +02:00
parent 36623d1687
commit 6b2117049c
@@ -12,7 +12,7 @@ patch(ChatWindowService.prototype, "mail/core/web", {
// chat window was opened from the messaging menu. In that
// case it should be re-opened to simulate it was always
// there in the background.
document.querySelector(".o_menu_systray i[aria-label='Messages']").click();
document.querySelector(".o_menu_systray i[aria-label='Messages']")?.click();
// ensure messaging menu is opened before chat window is closed
await Promise.resolve();
}