aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-07 10:40:02 -0800
committerAdam Soltys <[email protected]>2026-03-07 10:40:02 -0800
commit4437763b8dd21d2d13420146895b5fe29f72cc4b (patch)
treec36bae39b23c1297b727f0c581cdaed7ba742496
parent4237e418f7332f9edfad30964d2d6a51aa6c1db2 (diff)
downloadcoinos-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]>
-rw-r--r--lib/dmNotifications.ts16
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);
}
};