DEV: appEvents when desktop/push JS notifications are opened (#25823)

This commit is contained in:
Mark VanLandingham 2024-02-26 09:00:39 -06:00 committed by GitHub
parent ff9c6ce934
commit 7adedfa37a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -259,6 +259,11 @@ export default {
@bind
onAlert(data) {
return onNotification(data, this.siteSettings, this.currentUser);
return onNotification(
data,
this.siteSettings,
this.currentUser,
this.appEvents
);
},
};

View File

@ -144,7 +144,7 @@ function isIdle() {
}
// Call-in point from message bus
async function onNotification(data, siteSettings, user) {
async function onNotification(data, siteSettings, user, appEvents) {
if (!liveEnabled) {
return;
}
@ -187,6 +187,7 @@ async function onNotification(data, siteSettings, user) {
});
notification.onclick = () => {
DiscourseURL.routeTo(data.post_url);
appEvents.trigger("desktop-notification-opened", { url: data.post_url });
notification.close();
};

View File

@ -47,7 +47,7 @@ export function isPushNotificationsEnabled(user) {
);
}
export function register(user, router) {
export function register(user, router, appEvents) {
if (!isPushNotificationsSupported()) {
return;
}
@ -74,6 +74,7 @@ export function register(user, router) {
navigator.serviceWorker.addEventListener("message", (event) => {
if ("url" in event.data) {
router.transitionTo(event.data.url);
appEvents.trigger("push-notification-opened", { url: event.data.url });
}
});
}