From 5f6722b91711f6de416cf1b25ca848a32fb25b4a Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 31 Oct 2025 11:52:24 +0100 Subject: [PATCH] Add message notif --- backend/api/src/helpers/private-messages.ts | 4 ++++ backend/api/src/save-subscription-mobile.ts | 18 +++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/api/src/helpers/private-messages.ts b/backend/api/src/helpers/private-messages.ts index 06d5bb5..47cc7f2 100644 --- a/backend/api/src/helpers/private-messages.ts +++ b/backend/api/src/helpers/private-messages.ts @@ -293,6 +293,7 @@ async function sendMobileNotifications( interface PushPayload { title: string body: string + url: string data?: Record } @@ -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 } diff --git a/backend/api/src/save-subscription-mobile.ts b/backend/api/src/save-subscription-mobile.ts index 4edd0b8..6894332 100644 --- a/backend/api/src/save-subscription-mobile.ts +++ b/backend/api/src/save-subscription-mobile.ts @@ -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);