mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
DEV: appEvents when desktop/push JS notifications are opened (#25823)
This commit is contained in:
parent
ff9c6ce934
commit
7adedfa37a
|
@ -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
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user