Skip to content

Commit 5f6722b

Browse files
committed
Add message notif
1 parent fdcd4d4 commit 5f6722b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

backend/api/src/helpers/private-messages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ async function sendMobileNotifications(
293293
interface PushPayload {
294294
title: string
295295
body: string
296+
url: string
296297
data?: Record<string, string>
297298
}
298299

@@ -302,6 +303,9 @@ export async function sendPushToToken(token: string, payload: PushPayload) {
302303
notification: {
303304
title: payload.title,
304305
body: payload.body,
306+
data: {
307+
url: payload.url,
308+
},
305309
},
306310
data: payload.data, // optional custom key-value pairs
307311
}

backend/api/src/save-subscription-mobile.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ export const saveSubscriptionMobile: APIHandler<'save-subscription-mobile'> = as
1212

1313
try {
1414
const pg = createSupabaseDirectClient()
15-
// Check if a subscription already exists
16-
const exists = await pg.oneOrNone(
17-
'select id from push_subscriptions_mobile where token = $1',
18-
[token]
15+
await pg.none(`
16+
insert into push_subscriptions_mobile(token, platform, user_id)
17+
values ($1, $2, $3)
18+
on conflict(token) do update set platform = excluded.platform,
19+
user_id = excluded.user_id
20+
`,
21+
[token, 'android', userId]
1922
);
20-
21-
if (!exists) {
22-
await pg.none(`insert into push_subscriptions_mobile(token, platform, user_id) values($1, $2, $3) `,
23-
[token, 'android', userId]
24-
);
25-
}
26-
2723
return {success: true};
2824
} catch (err) {
2925
console.error('Error saving subscription', err);

0 commit comments

Comments
 (0)