[FIX] mail: ensure that voice threshold is updated across tabs

Before this commit, updating the voice activation threshold in one tab
would not affect the other tabs as the localStorage was only read when
discuss was initialized.

This commit fixes this issue.

task-2679234

closes odoo/odoo#88154

X-original-commit: 80c81c70787952eb4fdc4b81210bdf2893210e1a
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Thanh Dodeur
2022-04-14 14:07:01 +02:00
committed by Alexandre Kühn
parent 71050fb0fe
commit 557bb28cff
@@ -1,5 +1,7 @@
/** @odoo-module **/
import { browser } from "@web/core/browser/browser";
import { registerModel } from '@mail/model/model_core';
import { attr, many, one } from '@mail/model/model_field';
import { clear, insertAndReplace } from '@mail/model/model_field_command';
@@ -10,8 +12,10 @@ registerModel({
lifecycleHooks: {
_created() {
this._loadLocalSettings();
browser.addEventListener('storage', this._onStorage);
},
_willDelete() {
browser.removeEventListener('storage', this._onStorage);
for (const timeout of Object.values(this.volumeSettingsTimeouts)) {
this.messaging.browser.clearTimeout(timeout);
}
@@ -183,6 +187,16 @@ registerModel({
});
}
},
/**
* @private
* @param {Event} ev
*/
async _onStorage(ev) {
if (ev.key === 'mail_user_setting_voice_threshold') {
this.update({ voiceActivationThreshold: ev.newValue });
await this.messaging.rtc.updateVoiceActivation();
}
},
/**
* @private
*/