From d01995b438fc2bde316f9cc7020c01d71cd9d288 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 16 Feb 2023 22:43:43 -0800 Subject: emit messages --- lib/nostr.js | 9 ++++++++- routes/nostr.js | 10 +++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/nostr.js b/lib/nostr.js index fdea9d62..2eb59ae7 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -1,6 +1,6 @@ import config from "$config"; import { Relay, RelayPool } from "nostr"; -import { broadcast } from "$lib/sockets"; +import { broadcast, emit } from "$lib/sockets"; import store from "$lib/store"; import { g, s, db } from "$lib/db"; import { nada, wait } from "$lib/utils"; @@ -40,6 +40,13 @@ export let fillPool = () => { // coinos.send(["EVENT", ev]); ev.user = await getUser(pubkey); // broadcast("event", ev); + + if (ev.kind === 4) { + let uid = await g(`user:${ev.tags[0][1]}`); + if (uid) ev.recipient = await g(`user:${uid}`); + ev.author = ev.user; + emit(uid, "event", ev); + } } } else if (sub.includes("profile")) { let { pubkey } = ev; diff --git a/routes/nostr.js b/routes/nostr.js index 47ceaa25..8d6f6c34 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -70,9 +70,13 @@ export default { messages = await Promise.all( messages.map(async id => { let m = await g(`ev:${id}`); - let k = m.pubkey === pubkey ? m.tags[0][1] : m.pubkey; - let uid = await g(`user:${k}`); - m.user = await g(`user:${uid}`); + + let aid = await g(`user:${m.pubkey}`); + m.author = await g(`user:${aid}`); + + let rid = await g(`user:${m.tags[0][1]}`); + m.recipient = await g(`user:${rid}`); + return m; }) ); -- cgit v1.2.3