From 4437763b8dd21d2d13420146895b5fe29f72cc4b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 7 Mar 2026 10:40:02 -0800 Subject: include raw event in push payload for data transport Forward kind 445 Nostr events through push notifications so the client can process messages instantly without relying on WebSockets. Includes a 3KB size guard for the ~4KB push payload limit. Co-Authored-By: Claude Opus 4.6 --- lib/dmNotifications.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/dmNotifications.ts b/lib/dmNotifications.ts index ca6b032a..161920d8 100644 --- a/lib/dmNotifications.ts +++ b/lib/dmNotifications.ts @@ -13,7 +13,7 @@ if (config.vapid) { // Push notification delivery // --------------------------------------------------------------------------- -const sendPush = async (pubkey: string, url = "/messages") => { +const sendPush = async (pubkey: string, url = "/messages", event?: any) => { try { const user = await getUser(pubkey); if (!user?.id) return; @@ -23,11 +23,19 @@ const sendPush = async (pubkey: string, url = "/messages") => { l(`push to ${user.username} (${subscriptions.length} subs)`); - const payload = JSON.stringify({ + const payloadObj: any = { title: "New message", body: "You have a new encrypted message", url, - }); + }; + + // Include the raw event for push-as-data-transport (size guard for ~4KB push limit) + if (event) { + const eventStr = JSON.stringify(event); + if (eventStr.length < 3000) payloadObj.event = eventStr; + } + + const payload = JSON.stringify(payloadObj); for (const s of subscriptions as any) { webpush @@ -78,7 +86,7 @@ const handleGroupMessage = async (event: any) => { const sender = event.pubkey; for (const member of group.members) { - if (member !== sender) sendPush(member); + if (member !== sender) sendPush(member, "/messages", event); } }; -- cgit v1.2.3