[IMP] im_livechat, mail: improve onchange method

This commit improves the mail `onChange` method by adding
the support for multiple keys. This will make the code shorter
and easier to read.

closes odoo/odoo#133778

Signed-off-by: Didier Debondt (did) <did@odoo.com>
This commit is contained in:
tsm-odoo
2023-08-31 16:05:49 +00:00
parent 1015d7bd21
commit f9dcb907f0
3 changed files with 12 additions and 25 deletions
@@ -32,23 +32,11 @@ patch(Thread, {
author: thread.operator,
});
}
onChange(thread, "state", () => {
onChange(thread, ["state", "seen_message_id", "message_unread_counter"], () => {
if (![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(livechatService.state)) {
livechatService.updateSession({
state: thread.state,
});
}
});
onChange(thread, "seen_message_id", () => {
if (![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(livechatService.state)) {
livechatService.updateSession({
seen_message_id: thread.seen_message_id,
});
}
});
onChange(thread, "message_unread_counter", () => {
if (![SESSION_STATE.CLOSED, SESSION_STATE.NONE].includes(livechatService.state)) {
livechatService.updateSession({
channel: thread.channel,
});
}
@@ -142,22 +142,15 @@ export class Rtc {
this.toggleVideo("camera", true);
}
});
onChange(this.userSettingsService, "edgeBlurAmount", () => {
onChange(this.userSettingsService, ["edgeBlurAmount", "backgroundBlurAmount"], () => {
if (this.blurManager) {
this.blurManager.edgeBlur = this.userSettingsService.edgeBlurAmount;
}
});
onChange(this.userSettingsService, "backgroundBlurAmount", () => {
if (this.blurManager) {
this.blurManager.backgroundBlur = this.userSettingsService.backgroundBlurAmount;
}
});
onChange(this.userSettingsService, "voiceActivationThreshold", async () => {
await this.linkVoiceActivation();
});
onChange(this.userSettingsService, "usePushToTalk", async () => {
await this.linkVoiceActivation();
});
onChange(this.userSettingsService, ["voiceActivationThreshold", "usePushToTalk"], () =>
this.linkVoiceActivation()
);
onChange(this.userSettingsService, "audioInputDeviceId", async () => {
if (this.state.selfSession) {
await this.resetAudioTrack({ force: true });
+7 -1
View File
@@ -41,10 +41,16 @@ export function isDragSourceExternalFile(dataTransfer) {
/**
* @param {Object} target
* @param {string} key
* @param {string|string[]} key
* @param {Function} callback
*/
export function onChange(target, key, callback) {
if (Array.isArray(key)) {
for (const k of key) {
onChange(target, k, callback);
}
return;
}
const proxy = reactive(target, () => {
void proxy[key];
if (proxy[key] instanceof Object) {