aboutsummaryrefslogtreecommitdiffstats
path: root/routes/events.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-12-27 22:51:33 -0800
committerAdam Soltys <[email protected]>2022-12-27 22:51:33 -0800
commit2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74 (patch)
treececb95f1c16ba3f1cf020bedc945706032df9d64 /routes/events.js
parenta487b5a2b80d270771f9932c17d2b6babf0fd49a (diff)
downloadcoinos-server-2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74.tar.gz
coinos-server-2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74.zip
follower endpoints
Diffstat (limited to 'routes/events.js')
-rw-r--r--routes/events.js32
1 files changed, 20 insertions, 12 deletions
diff --git a/routes/events.js b/routes/events.js
index 07062140..4dcc44f0 100644
--- a/routes/events.js
+++ b/routes/events.js
@@ -5,33 +5,41 @@ import { pool } from "$lib/nostr";
import store from "$lib/store";
import { wait } from "$lib/utils";
-app.get("/:pubkey/events", async (req, res) => {
+app.get("/nostr/:pubkey", async (req, res) => {
try {
let { pubkey } = req.params;
+
store.fetching[pubkey] = true;
store.timeouts[pubkey] = setTimeout(
() => (store.fetching[pubkey] = false),
500
);
- let user = await db.User.findOne({
- where: { pubkey }
- });
+ let user = JSON.parse(await redis.get(`user:${pubkey}`));
- if (!user) user = { username: pubkey.substr(0,6), pubkey, anon: true }
- await redis.set(`user:${pubkey}`, JSON.stringify(user));
+ if (!user) {
+ user = await db.User.findOne({
+ where: { pubkey }
+ });
+ }
+
+ if (!user) user = { username: pubkey.substr(0, 6), pubkey, anon: true };
+
+ let { since } = user;
pool.subscribe(pubkey, {
- limit: 500,
+ since,
kinds: [1],
authors: [pubkey]
});
- let events = [];
- await wait(() => !store.fetching[pubkey], 10, 10);
- for (let id of await redis.sMembers(pubkey)) {
- events.push(JSON.parse(await redis.get(`ev:${id}`)));
- }
+ user.since = Math.round(Date.now() / 1000);
+ await redis.set(`user:${pubkey}`, JSON.stringify(user));
+
+ await wait(() => !store.fetching[pubkey], 100, 100);
+ let events = (
+ await redis.mGet((await redis.sMembers(pubkey)).map(k => "ev:" + k))
+ ).map(JSON.parse);
res.send(events);
} catch (e) {