[FIX] mail: fix push to talk key detection

Before this commit, the push to talk key combination was wrongly
detected. Indeed, it was dependent on which key was pressed first.

Steps to reproduce:
- Register "ctrl + alt" as the push to talk key
- Press control then alt, push to talk does not work
- Press alt then control, push to talk works
- If you unpress the alt key, the push to talk will stop as expected
- If you unpress the control key, the push to talk will keep going

This commit fixes the issue.

closes odoo/odoo#134981

X-original-commit: 3e4ed2a43ad23116c095af67cb7e5736a9854820
Signed-off-by: Thanh Son Dodeur (tso) <tso@odoo.com>
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
This commit is contained in:
tsm-odoo
2023-09-11 15:22:12 +00:00
parent d1c5c4718f
commit 39a4d85de3
3 changed files with 40 additions and 15 deletions
@@ -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) {
@@ -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) {
@@ -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;