aboutsummaryrefslogtreecommitdiffstats
path: root/src/nip29-client.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/nip29-client.js')
-rw-r--r--src/nip29-client.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nip29-client.js b/src/nip29-client.js
index 4c27b64..cfbd171 100644
--- a/src/nip29-client.js
+++ b/src/nip29-client.js
@@ -125,7 +125,7 @@ export function nip29Client({ scope, pubkey, identity, on, listRelays, store = m
function load() {
if (!loaded)
loaded = store.all().then((all) => {
- for (const [k, v] of all) if (k.startsWith('g:') && v && v.relay && v.gid) groups.set(v.id, { ...v, log: v.log || [] });
+ for (const [k, v] of all) if (k.startsWith('g:') && v && v.relay && v.gid) groups.set(v.id, { ...v, log: v.log || [], unreachable: '' });
const l = all.get('list');
if (l && Array.isArray(l.tags)) list = l;
}).catch((e) => dlog('nip29: store', e));
@@ -171,8 +171,12 @@ export function nip29Client({ scope, pubkey, identity, on, listRelays, store = m
function subscribe(g) {
if (subs.has(g.id) || stopped) return;
const since = g.seen ? g.seen - 60 : undefined;
+ // a relay that can't be reached (groups.0xchat.com stopped resolving)
+ // is said on the group's row instead of "0 members"
+ const reached = () => { if (g.unreachable) { g.unreachable = ''; touch(g); emit('loaded', g); } };
const a = subscribeAuthed([g.relay], { kinds: CHAT_KINDS, '#h': [g.gid], limit: 300, ...(since ? { since } : {}) },
- (ev) => { if (ev.tags.some((x) => x[0] === 'h' && x[1] === g.gid)) take(g, ev); }, { onauth });
+ (ev) => { reached(); if (ev.tags.some((x) => x[0] === 'h' && x[1] === g.gid)) take(g, ev); },
+ { onauth, onclose: (why) => { if (!g.log.length && !g.members.length) { g.unreachable = String((why && why[0]) || 'unreachable'); touch(g); emit('loaded', g); } } });
// metadata: only what the group's own relay signed (the copies other
// relays carry are read nowhere)
const b = subscribeAuthed([g.relay], { kinds: META_KINDS, '#d': [g.gid] },
@@ -238,6 +242,7 @@ export function nip29Client({ scope, pubkey, identity, on, listRelays, store = m
await load();
leftNow.delete(keyOf(a.relay, a.gid));
const g = record(a.relay, a.gid);
+ g.joinedAt = now(); // sorts a group joined here, still quiet, as new
touch(g);
subscribe(g);
emit('joined', g);