aboutsummaryrefslogtreecommitdiffstats
path: root/Dockerfile.base
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-10-26 01:27:43 -0700
committerAdam Soltys <[email protected]>2022-10-26 01:27:43 -0700
commit3d901bc14fe78293bf9fbf9fa804cb637b9a32e1 (patch)
tree49fa202af6d0eea658c168d4eb1bfc6f439179a9 /Dockerfile.base
parent9c95c7889ff6901bee13e77860172e03500cd9cd (diff)
downloadcoinos-ui-3d901bc14fe78293bf9fbf9fa804cb637b9a32e1.tar.gz
coinos-ui-3d901bc14fe78293bf9fbf9fa804cb637b9a32e1.zip
copy update
Diffstat (limited to 'Dockerfile.base')
0 files changed, 0 insertions, 0 deletions
2d16bfe58facc9ebb53847b3316a'>9ebd4105 ^
31603960 ^
9ebd4105 ^
aa662369 ^



a487b5a2 ^

aa662369 ^















a487b5a2 ^









aa662369 ^



9ebd4105 ^
a487b5a2 ^





aa662369 ^


a487b5a2 ^
728ac80f ^



aa662369 ^


9ebd4105 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72


                                         

                               

                                                                       
                                      
 
                          
                                                   
                                        

   
           
              



                                            

                          















                                                                         









                                                                    



                                           
 





                                                                  


                                                         
                                    



                                               


                   

   
import { Relay, RelayPool } from "nostr";
import { got } from "got";
import { broadcast } from "$lib/sockets";
import store from "$lib/store";
import redis from "$lib/redis";

const { relays } = await got("https://nostr.watch/relays.json").json();
export const pool = RelayPool(relays);

pool.on("open", relay => {
  if (relay.url.includes("coinos")) coinos = relay;
  relay.subscribe("live", { limit: 1 });
});

let coinos;
let seen = [];
let timeout;
pool.on("event", async (relay, sub, ev) => {
  try {
    if (sub === "live") {
      let { pubkey } = ev;

      if (Math.abs(Math.floor(Date.now() / 1000) - ev.created_at) > 7200)
        return;

      if (seen.includes(ev.id)) return;
      seen.push(ev.id);
      seen.length > 1000 && seen.shift();

      if (coinos && ev.kind < 5) {
        let parsed;
        try {
          parsed = JSON.parse(ev.content);
        } catch (e) {
          parsed = ev.content;
        }

        coinos.send(["EVENT", ev]);

        ev.user = JSON.parse(await redis.get(`user:${pubkey}`)) || {
          username: pubkey.substr(0, 6),
          pubkey,
          anon: true
        };

        if (ev.kind === 1) {
          broadcast("event", ev);
        }
      }
    } else {
      let pubkey = sub;
      clearTimeout(store.timeouts[pubkey]);

      ev.user = JSON.parse(await redis.get(`user:${pubkey}`)) || {
        username: pubkey.substr(0, 6),
        pubkey,
        anon: true
      };

      await redis.sAdd(pubkey, ev.id);
      await redis.set(`ev:${ev.id}`, JSON.stringify(ev));

      store.fetching[pubkey] = true;
      store.timeouts[pubkey] = setTimeout(
        () => (store.fetching[pubkey] = false),
        100
      );
    }
  } catch (e) {
    console.log(e);
  }
});