diff options
| author | Adam Soltys <[email protected]> | 2026-03-07 10:40:02 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-07 10:40:02 -0800 |
| commit | 4437763b8dd21d2d13420146895b5fe29f72cc4b (patch) | |
| tree | c36bae39b23c1297b727f0c581cdaed7ba742496 /lib | |
| parent | 4237e418f7332f9edfad30964d2d6a51aa6c1db2 (diff) | |
| download | coinos-server-4437763b8dd21d2d13420146895b5fe29f72cc4b.tar.gz coinos-server-4437763b8dd21d2d13420146895b5fe29f72cc4b.zip | |
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 <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dmNotifications.ts | 16 |
1 files 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); } }; |
