diff --git a/addons/mail/static/src/core/common/user_settings_service.js b/addons/mail/static/src/core/common/user_settings_service.js index eb32b744220..84e898584af 100644 --- a/addons/mail/static/src/core/common/user_settings_service.js +++ b/addons/mail/static/src/core/common/user_settings_service.js @@ -108,9 +108,13 @@ export class UserSettings { * @param {event} ev */ async setPushToTalkKey(ev) { - const pushToTalkKey = `${ev.shiftKey || ""}.${ev.ctrlKey || ev.metaKey || ""}.${ + const nonElligibleKeys = new Set(["Shift", "Control", "Alt", "Meta"]); + let pushToTalkKey = `${ev.shiftKey || ""}.${ev.ctrlKey || ev.metaKey || ""}.${ ev.altKey || "" - }.${ev.key === " " ? "Space" : ev.key}`; + }`; + if (!nonElligibleKeys.has(ev.key)) { + pushToTalkKey += `.${ev.key === " " ? "Space" : ev.key}`; + } this.pushToTalkKey = pushToTalkKey; this._saveSettings(); } @@ -149,25 +153,43 @@ export class UserSettings { // methods + buildKeySet({ shiftKey, ctrlKey, altKey, key }) { + const keys = new Set(); + if (key) { + keys.add(key === "Meta" ? "Alt" : key); + } + if (shiftKey) { + keys.add("Shift"); + } + if (ctrlKey) { + keys.add("Control"); + } + if (altKey) { + keys.add("Alt"); + } + return keys; + } + /** * @param {event} ev * @param {Object} param1 - * @param {boolean} param1.ignoreModifiers */ - isPushToTalkKey(ev, { ignoreModifiers = false } = {}) { + isPushToTalkKey(ev) { if (!this.usePushToTalk || !this.pushToTalkKey) { return false; } - const { key, shiftKey, ctrlKey, altKey } = this.pushToTalkKeyFormat(); - if (ignoreModifiers) { - return ev.key === key; + const [shiftKey, ctrlKey, altKey, key] = this.pushToTalkKey.split("."); + const settingsKeySet = this.buildKeySet({ shiftKey, ctrlKey, altKey, key }); + const eventKeySet = this.buildKeySet({ + shiftKey: ev.shiftKey, + ctrlKey: ev.ctrlKey, + altKey: ev.altKey, + key: ev.key, + }); + if (ev.type === "keydown") { + return [...settingsKeySet].every((key) => eventKeySet.has(key)); } - return ( - ev.key === key && - ev.shiftKey === shiftKey && - ev.ctrlKey === ctrlKey && - ev.altKey === altKey - ); + return settingsKeySet.has(ev.key === "Meta" ? "Alt" : ev.key); } pushToTalkKeyFormat() { if (!this.pushToTalkKey) { diff --git a/addons/mail/static/src/discuss/call/common/call_settings.js b/addons/mail/static/src/discuss/call/common/call_settings.js index a771daaf14a..42e2e98830f 100644 --- a/addons/mail/static/src/discuss/call/common/call_settings.js +++ b/addons/mail/static/src/discuss/call/common/call_settings.js @@ -39,7 +39,10 @@ export class CallSettings extends Component { get pushToTalkKeyText() { const { shiftKey, ctrlKey, altKey, key } = this.userSettings.pushToTalkKeyFormat(); const f = (k, name) => (k ? name : ""); - return `${f(ctrlKey, "Ctrl + ")}${f(altKey, "Alt + ")}${f(shiftKey, "Shift + ")}${key}`; + const keys = [f(ctrlKey, "Ctrl"), f(altKey, "Alt"), f(shiftKey, "Shift"), key].filter( + Boolean + ); + return keys.join(" + "); } _onKeyDown(ev) { diff --git a/addons/mail/static/src/discuss/call/common/rtc_service.js b/addons/mail/static/src/discuss/call/common/rtc_service.js index 7671220dfb0..ed403f4e799 100644 --- a/addons/mail/static/src/discuss/call/common/rtc_service.js +++ b/addons/mail/static/src/discuss/call/common/rtc_service.js @@ -214,7 +214,7 @@ export class Rtc { if ( !this.state.channel || !this.userSettingsService.usePushToTalk || - !this.userSettingsService.isPushToTalkKey(ev, { ignoreModifiers: true }) || + !this.userSettingsService.isPushToTalkKey(ev) || !this.state.selfSession.isTalking ) { return;