fix stale relays bug

Pulling data from kind 3 event instead of kind 65 since it's more widely supported. Also, turned off the cache to try to ensure that most recent relay data is displayed.
This commit is contained in:
Sam Samskies 2023-02-20 16:52:03 -06:00
parent eddba62575
commit 6254149c2a
No known key found for this signature in database
GPG Key ID: E3F697EE1B6EB156
1 changed files with 17 additions and 20 deletions

View File

@ -7,29 +7,26 @@ export default function useRelaysFeed(pubkey: HexKey) {
const sub = useMemo(() => {
const x = new Subscriptions();
x.Id = `relays:${pubkey.slice(0, 12)}`;
x.Kinds = new Set([EventKind.Relays]);
x.Kinds = new Set([EventKind.ContactList]);
x.Authors = new Set([pubkey]);
x.Limit = 1;
return x;
}, [pubkey]);
const relays = useSubscription(sub, { leaveOpen: false, cache: true });
const notes = relays.store.notes;
const tags = notes.slice(-1)[0]?.tags || [];
return tags.reduce((rs, tag) => {
const [t, url, ...settings] = tag;
if (t === "r") {
return [
...rs,
{
url,
settings: {
read: settings.length === 0 || settings.includes("read"),
write: settings.length === 0 || settings.includes("write"),
},
},
];
}
return rs;
}, [] as FullRelaySettings[]);
const relays = useSubscription(sub, { leaveOpen: false, cache: false });
const eventContent = relays.store.notes[0]?.content;
if (!eventContent) {
return [] as FullRelaySettings[];
}
try {
return Object.entries(JSON.parse(eventContent)).map(([url, settings]) => ({
url,
settings,
})) as FullRelaySettings[];
} catch (error) {
console.error(error);
return [] as FullRelaySettings[];
}
}