Skip to content

Commit 2f26198

Browse files
fix(notifications): update onMessage show notification handler (#2127)
1 parent d1a9df6 commit 2f26198

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

frontend/src/utils/pushNotifications.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ export const showNotification = (payload: any) => {
66
const registration = window.frappePushNotification.serviceWorkerRegistration
77
if (!registration) return
88

9-
const notificationTitle = payload?.notification?.title
9+
const data = payload?.data ?? {}
10+
const notification = payload?.notification ?? {}
11+
12+
13+
const notificationTitle = data.title || notification.title
1014
const notificationOptions = {
1115
body: payload?.notification?.body || "",
1216
}
13-
if (payload?.data?.image) {
17+
if (data.image) {
1418
// @ts-ignore
15-
notificationOptions["icon"] = payload.data.image
19+
notificationOptions["icon"] = data.image
1620
}
1721

18-
if (payload.data.creation) {
22+
if (data.creation) {
1923
// @ts-ignore
20-
notificationOptions["timestamp"] = payload.data.creation
24+
notificationOptions["timestamp"] = data.creation
2125
}
22-
let url = `${payload.data.base_url}/raven/channel/${payload.data.channel_id}`
26+
let url = `${data.base_url}/raven/channel/${data.channel_id}`
2327

24-
if (payload.data.message_url) {
25-
url = payload.data.message_url
28+
if (data.message_url) {
29+
url = data.message_url
2630
}
2731

2832
if (isChrome()) {
@@ -31,7 +35,7 @@ export const showNotification = (payload: any) => {
3135
url: url,
3236
}
3337
} else {
34-
if (payload?.data?.click_action) {
38+
if (data.click_action) {
3539
// @ts-ignore
3640
notificationOptions["actions"] = [
3741
{
@@ -43,4 +47,4 @@ export const showNotification = (payload: any) => {
4347
}
4448

4549
registration.showNotification(notificationTitle, notificationOptions)
46-
}
50+
}

0 commit comments

Comments
 (0)