From c7ef46977a87919f6554e2771be32d7bd3336a1d Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Wed, 28 Sep 2022 09:23:56 +0000 Subject: [PATCH] [IMP] bus: remove websocket connection lost toast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, loosing the websocket connection would have resulted in a toast being displayed. This toast is seen as degrading the UX experience and is redundant with the already existing "Connection Lost" toast. This PR removes it. closes odoo/odoo#101501 X-original-commit: a26c8aa18ad6c4f52a4526e20d570ca1bc4123f2 Signed-off-by: Sébastien Theys (seb) Signed-off-by: Stockbauer Matthieu (tsm) --- addons/bus/static/src/services/bus_service.js | 22 +------- addons/bus/static/tests/bus_tests.js | 53 ------------------- 2 files changed, 2 insertions(+), 73 deletions(-) diff --git a/addons/bus/static/src/services/bus_service.js b/addons/bus/static/src/services/bus_service.js index c47fce81d09..4354bdd6c41 100644 --- a/addons/bus/static/src/services/bus_service.js +++ b/addons/bus/static/src/services/bus_service.js @@ -1,17 +1,10 @@ /** @odoo-module **/ -import { WEBSOCKET_CLOSE_CODES } from "@bus/workers/websocket_worker"; - import { browser } from "@web/core/browser/browser"; import { registry } from '@web/core/registry'; import { session } from '@web/session'; const { EventBus } = owl; -const NO_POPUP_CLOSE_CODES = [ - WEBSOCKET_CLOSE_CODES.SESSION_EXPIRED, - WEBSOCKET_CLOSE_CODES.KEEP_ALIVE_TIMEOUT, - WEBSOCKET_CLOSE_CODES.TRY_LATER, -]; /** * Communicate with a SharedWorker in order to provide a single websocket @@ -24,7 +17,7 @@ const NO_POPUP_CLOSE_CODES = [ * @emits notification */ export const busService = { - dependencies: ['localization', 'multi_tab', 'notification'], + dependencies: ['localization', 'multi_tab'], start(env, { multi_tab: multiTab }) { if (session.dbuuid && multiTab.getSharedValue('dbuuid') !== session.dbuuid) { @@ -36,7 +29,6 @@ export const busService = { const worker = new workerClass('/bus/websocket_worker_bundle', { name: 'SharedWorker' in window ? 'odoo:websocket_shared_worker' : 'odoo:websocket_worker', }); - let removeConnectionLostNotification; /** * Send a message to the worker. @@ -65,17 +57,7 @@ export const busService = { function handleMessage(messageEv) { const { type } = messageEv.data; let { data } = messageEv.data; - // Do not trigger the connection lost pop up if the reconnecting - // event is caused by a session expired/keep_alive_timeout. - if (type === 'reconnecting' && !NO_POPUP_CLOSE_CODES.includes(data.closeCode)) { - removeConnectionLostNotification = env.services.notification.add( - env._t("Websocket connection lost. Trying to reconnect..."), - { sticky: true }, - ); - } else if (type === 'reconnect' && removeConnectionLostNotification) { - removeConnectionLostNotification(); - removeConnectionLostNotification = null; - } else if (type === 'notification') { + if (type === 'notification') { multiTab.setSharedValue('last_notification_id', data[data.length - 1].id); data = data.map(notification => notification.message); } diff --git a/addons/bus/static/tests/bus_tests.js b/addons/bus/static/tests/bus_tests.js index c9c1e874d39..ca13a8bcf2d 100644 --- a/addons/bus/static/tests/bus_tests.js +++ b/addons/bus/static/tests/bus_tests.js @@ -13,9 +13,6 @@ const { registry } = require("@web/core/registry"); const { session } = require('@web/session'); const { makeDeferred, nextTick, patchWithCleanup } = require("@web/../tests/helpers/utils"); const { makeTestEnv } = require('@web/../tests/helpers/mock_env'); -const { createWebClient } = require("@web/../tests/webclient/helpers"); - -const { afterNextRender } = owl.App; QUnit.module('Bus', { beforeEach: function () { @@ -311,56 +308,6 @@ QUnit.module('Bus', { ]); }); - QUnit.test('displays reconnect notification', async (assert) => { - assert.expect(3); - - let startPromise = Promise.resolve(); - patchWebsocketWorkerWithCleanup({ - async _start() { - const originalStart = this._super; - await startPromise; - return originalStart(...arguments); - }, - }); - const pyEnv = await startServer(); - await createWebClient({}); - // prevent websocket to connect and notification to disappear - // before the assertion. - startPromise = makeDeferred(); - await afterNextRender(() => pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.ABNORMAL_CLOSURE)); - - assert.containsOnce(document.body, '.o_notification'); - assert.strictEqual( - document.querySelector('.o_notification .o_notification_content').textContent, - 'Websocket connection lost. Trying to reconnect...' - ); - // Wait for the worker to reconnect, post a message and the - // bus_service to receive it and remove the notification. - await afterNextRender(() => startPromise.resolve()); - assert.containsNone(document.body, '.o_notification'); - }); - - QUnit.test('does not display connection lost popup when refreshing the session', async (assert) => { - assert.expect(1); - - const pyEnv = await startServer(); - await createWebClient({}); - pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.SESSION_EXPIRED); - await nextTick(); - assert.containsNone(document.body, '.o_notification'); - }); - - - QUnit.test('does not display connection lost popup when refreshing the connection upon keep_alive_timeout', async (assert) => { - assert.expect(1); - - const pyEnv = await startServer(); - await createWebClient({}); - pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.KEEP_ALIVE_TIMEOUT); - await nextTick(); - assert.containsNone(document.body, '.o_notification'); - }); - QUnit.test('Last notification id is passed to the worker on service start', async function (assert) { const pyEnv = await startServer(); let updateLastNotificationDeferred = makeDeferred();