From f7307a8e2d627006dd6e72fe9c1e2e4d5c6e312a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 13 Feb 2023 13:03:36 -0800 Subject: nostr fixes --- lib/nostr.js | 23 ++++++++++++++--------- routes/nostr.js | 12 +++++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/nostr.js b/lib/nostr.js index 065fafb0..b6f5f50d 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -5,12 +5,13 @@ import store from "$lib/store"; import { g, s, db } from "$lib/db"; import { nada, wait } from "$lib/utils"; +export let coinos; export let pool; export let fillPool = () => { pool = RelayPool(config.relays); pool.on("open", relay => { - if (relay.url.includes(config.relay)) coinos = relay; + if (relay.url.includes(config.nostr)) coinos = relay; relay.subscribe("live", { limit: 1 }); }); @@ -61,7 +62,7 @@ export let fillPool = () => { coinos.send(ev); } else if (sub.includes("follows")) { let pubkey = sub.split(":")[0]; - await s(`${pubkey}:follows`, JSON.stringify(ev.tags)); + await s(`${pubkey}:follows`, ev.tags); for (let f of ev.tags) { let [_, followPubkey] = f; await db.sAdd(`${followPubkey}:followers`, pubkey); @@ -83,7 +84,6 @@ export let fillPool = () => { }); }; -export let coinos; let now = () => Math.round(Date.now() / 1000); let timeouts = {}; @@ -156,9 +156,14 @@ export let q = async ( let seen = []; -let getUser = async pubkey => - JSON.parse(await g(`user:${pubkey}`)) || { - username: pubkey.substr(0, 6), - pubkey, - anon: true - }; +let getUser = async pubkey => { + let id = await g(`user:${pubkey}`); + let user = await g(`user:${id}`); + return ( + user || { + username: pubkey.substr(0, 6), + pubkey, + anon: true + } + ); +}; diff --git a/routes/nostr.js b/routes/nostr.js index f006a23d..1ca6fad5 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -52,7 +52,6 @@ export default { async broadcast(req, res) { let { event } = req.body; - console.log("sending", event) pool.send(["EVENT", event]); res.send(event); }, @@ -81,7 +80,8 @@ export default { authors: [pubkey] }).catch(nada); - let user = await g(`user:${pubkey}`); + let uid = await g(`user:${pubkey}`); + let user = await g(`user:${uid}`); if (!user) user = { @@ -114,15 +114,17 @@ export default { ).catch(nada); for (let pubkey of pubkeys) { - let user = await g(`user:${pubkey}`); + let uid = await g(`user:${pubkey}`); + let user = await g(`user:${uid}`); if (!user || !user.updated) { - q(`${pubkey}:profile:f2`, { + await q(`${pubkey}:profile:f2`, { limit: 1, kinds: [0], authors: [pubkey] }).catch(nada); - user = await g(`user:${pubkey}`); + uid = await g(`user:${pubkey}`); + user = await g(`user:${uid}`); } if (!user) -- cgit v1.2.3