mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-18 14:55:18 -05:00
Add message notif
This commit is contained in:
@@ -293,6 +293,7 @@ async function sendMobileNotifications(
|
||||
interface PushPayload {
|
||||
title: string
|
||||
body: string
|
||||
url: string
|
||||
data?: Record<string, string>
|
||||
}
|
||||
|
||||
@@ -302,6 +303,9 @@ export async function sendPushToToken(token: string, payload: PushPayload) {
|
||||
notification: {
|
||||
title: payload.title,
|
||||
body: payload.body,
|
||||
data: {
|
||||
url: payload.url,
|
||||
},
|
||||
},
|
||||
data: payload.data, // optional custom key-value pairs
|
||||
}
|
||||
|
||||
@@ -12,18 +12,14 @@ export const saveSubscriptionMobile: APIHandler<'save-subscription-mobile'> = as
|
||||
|
||||
try {
|
||||
const pg = createSupabaseDirectClient()
|
||||
// Check if a subscription already exists
|
||||
const exists = await pg.oneOrNone(
|
||||
'select id from push_subscriptions_mobile where token = $1',
|
||||
[token]
|
||||
await pg.none(`
|
||||
insert into push_subscriptions_mobile(token, platform, user_id)
|
||||
values ($1, $2, $3)
|
||||
on conflict(token) do update set platform = excluded.platform,
|
||||
user_id = excluded.user_id
|
||||
`,
|
||||
[token, 'android', userId]
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
await pg.none(`insert into push_subscriptions_mobile(token, platform, user_id) values($1, $2, $3) `,
|
||||
[token, 'android', userId]
|
||||
);
|
||||
}
|
||||
|
||||
return {success: true};
|
||||
} catch (err) {
|
||||
console.error('Error saving subscription', err);
|
||||
|
||||
Reference in New Issue
Block a user