aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/notifications.ts19
-rw-r--r--routes/payments.ts1
2 files changed, 19 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 },
);
}
};
diff --git a/routes/payments.ts b/routes/payments.ts
index 00230c62..accb09fd 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -740,6 +740,7 @@ export default {
mqtt.publish(
username,
`pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`,
+ { qos: 1 },
);
res.send({ ok: true });