diff options
| author | Adam Soltys <[email protected]> | 2022-12-27 22:51:33 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-12-27 22:51:33 -0800 |
| commit | 2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74 (patch) | |
| tree | cecb95f1c16ba3f1cf020bedc945706032df9d64 /lib/utils.js | |
| parent | a487b5a2b80d270771f9932c17d2b6babf0fd49a (diff) | |
| download | coinos-server-2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74.tar.gz coinos-server-2d2c991645f3b0ac7fb3ad88afdad0bb67c28b74.zip | |
follower endpoints
Diffstat (limited to 'lib/utils.js')
| -rw-r--r-- | lib/utils.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js index 46267dbd..2854fefc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,3 +1,4 @@ +import store from "$lib/store"; import config from "$config"; import db from "$db"; import sequelize from "@sequelize/core"; @@ -37,6 +38,26 @@ export const getUser = async (username, transaction) => { user.haspin = !!user.pin; + let { pubkey } = user; + + if (pubkey) { + store.fetching[pubkey] = true; + store.timeouts[pubkey] = setTimeout( + () => (store.fetching[pubkey] = false), + 500 + ); + + coinos.subscribe(`${pubkey}:follows`, { + limit: 1, + kinds: [3], + authors: [pubkey] + }); + + await wait(() => !store.fetching[pubkey], 100, 10); + user.follows = JSON.parse(await redis.get(`${pubkey}:follows`)); + user.followers = await redis.sMembers(`${pubkey}:followers`); + } + return user; }; |
