This commit refactors discuss code to use OWL components and new tools and services in web/. Functionally, Discuss app should work relatively the same as before this commit. closes https://github.com/odoo/odoo/pull/110188 Related: https://github.com/odoo/enterprise/pull/38058 https://github.com/odoo/upgrade/pull/4423 closes odoo/odoo#110188 Related: odoo/upgrade#4423 Related: odoo/enterprise#38058 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Co-authored-by: Alexandre (aku) <aku@odoo.com> Co-authored-by: Didier (did) <did@odoo.com> Co-authored-by: Géry (ged) <ged@odoo.com> Co-authored-by: Louis (wil) <wil@odoo.com> Co-authored-by: Maël (mapa) <mapa@odoo.com> Co-authored-by: Maryam (maki) <maki@odoo.com> Co-authored-by: Sébastien (seb) <seb@odoo.com> Co-authored-by: Thanh (tso) <tso@odoo.com> Co-authored-by: Matthieu (tsm) <tsm@odoo.com> Co-authored-by: Zelong (zel) <zel@odoo.com>
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import { browser } from "@web/core/browser/browser";
|
|
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
|
|
|
/**
|
|
* Patch both the `Notification` and the `Permissions` API which are codependent
|
|
* based on the given value. Note that when `requestPermissionResult` is passed,
|
|
* the `change` event of the `Permissions` API will also be triggered.
|
|
*
|
|
* @param {"default" | "denied" | "granted"} permission
|
|
* @param {"default" | "denied" | "granted"} requestPermissionResult
|
|
*/
|
|
export function patchBrowserNotification(permission = "default", requestPermissionResult) {
|
|
if (!browser.Notification || !browser.navigator.permissions) {
|
|
return;
|
|
}
|
|
const notificationQueries = [];
|
|
patchWithCleanup(browser.navigator.permissions, {
|
|
async query({ name }) {
|
|
const result = await this._super(...arguments);
|
|
if (name === "notifications") {
|
|
Object.defineProperty(result, "state", {
|
|
get: () => (permission === "default" ? "prompt" : permission),
|
|
});
|
|
notificationQueries.push(result);
|
|
}
|
|
return result;
|
|
},
|
|
});
|
|
patchWithCleanup(browser.Notification, {
|
|
permission,
|
|
isPatched: true,
|
|
requestPermission() {
|
|
if (!requestPermissionResult) {
|
|
return this._super(...arguments);
|
|
}
|
|
this.permission = requestPermissionResult;
|
|
for (const query of notificationQueries) {
|
|
query.permission = requestPermissionResult;
|
|
query.dispatchEvent(new Event("change"));
|
|
}
|
|
return requestPermissionResult;
|
|
},
|
|
});
|
|
}
|