diff options
| author | Adam Soltys <[email protected]> | 2023-02-16 22:43:43 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-16 22:43:43 -0800 |
| commit | d01995b438fc2bde316f9cc7020c01d71cd9d288 (patch) | |
| tree | a6d5cf9cec203b6c77cdf5f2b4baef2202baca60 | |
| parent | 8b9497ec3349a584c90d2ac782c634f7f328c19f (diff) | |
| download | coinos-server-d01995b438fc2bde316f9cc7020c01d71cd9d288.tar.gz coinos-server-d01995b438fc2bde316f9cc7020c01d71cd9d288.zip | |
emit messages
| -rw-r--r-- | lib/nostr.js | 9 | ||||
| -rw-r--r-- | 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; }) ); |
