diff options
| author | Adam Soltys <[email protected]> | 2026-09-14 13:19:52 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-14 13:19:52 -0700 |
| commit | 19f73ae9cf2afffbbb2abc71eb80c6d5bdccca52 (patch) | |
| tree | 33ee5d1ae99772c6d25e3d69d72633448eccfa21 /lib/notifications.ts | |
| parent | cdda2d34d26bd8fb310867022130e4a59f67d13c (diff) | |
| download | coinos-server-19f73ae9cf2afffbbb2abc71eb80c6d5bdccca52.tar.gz coinos-server-19f73ae9cf2afffbbb2abc71eb80c6d5bdccca52.zip | |
printer: publish receipts at QoS 1 and clean LNURL metadata memos
Receipts were published at QoS 0, so a printer that was briefly offline
(WiFi blip, keepalive timeout) never received them. QoS 1 lets the broker
queue them for printers that hold a persistent session.
LNURL-pay invoices carry the raw metadata array as their memo when the
payer leaves no comment; unwrap the text/plain entry before printing.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_011cCouc5ASRXHDp5esLciEK
Diffstat (limited to 'lib/notifications.ts')
| -rw-r--r-- | lib/notifications.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/notifications.ts b/lib/notifications.ts index 3fa880c4..fe245c61 100644 --- a/lib/notifications.ts +++ b/lib/notifications.ts @@ -19,6 +19,22 @@ if (config.vapid) { ); } + +// LNURL-pay invoices carry the raw metadata array as their memo when the +// payer left no comment, e.g. [["text/plain","Paying [email protected]"],...]. +// Receipts should show just the human-readable text. +const printerMemo = (memo) => { + if (typeof memo !== "string" || !memo.startsWith("[")) return memo; + try { + const meta = JSON.parse(memo); + if (Array.isArray(meta)) { + const plain = meta.find((m) => Array.isArray(m) && m[0] === "text/plain"); + if (plain) return plain[1]; + } + } catch (e) {} + return memo; +}; + export const notify = async (p, user, withdrawal) => { emit(user.id, "payment", p); let { username } = user; @@ -74,7 +90,8 @@ export const notify = async (p, user, withdrawal) => { if (!mqtt.connected) await mqtt.reconnect(); mqtt.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}:${p.memo}:${p.items}`, + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}:${printerMemo(p.memo)}:${p.items}`, + { qos: 1 }, ); } }; |
