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 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'lib') 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 + } + ); +}; -- cgit v1.2.3