refactor: dont get user relays
This commit is contained in:
@ -37,13 +37,7 @@ export function useLoginEvents(pubkey?: string, leaveOpen = false) {
|
|||||||
})
|
})
|
||||||
.withFilter()
|
.withFilter()
|
||||||
.authors([pubkey])
|
.authors([pubkey])
|
||||||
.kinds([
|
.kinds([EventKind.ContactList, MUTED, USER_EMOJIS, USER_CARDS]);
|
||||||
EventKind.ContactList,
|
|
||||||
EventKind.Relays,
|
|
||||||
MUTED,
|
|
||||||
USER_EMOJIS,
|
|
||||||
USER_CARDS,
|
|
||||||
]);
|
|
||||||
return b;
|
return b;
|
||||||
}, [pubkey, leaveOpen]);
|
}, [pubkey, leaveOpen]);
|
||||||
|
|
||||||
@ -70,9 +64,6 @@ export function useLoginEvents(pubkey?: string, leaveOpen = false) {
|
|||||||
if (ev?.kind === EventKind.ContactList) {
|
if (ev?.kind === EventKind.ContactList) {
|
||||||
Login.setFollows(ev.tags, ev.content, ev.created_at);
|
Login.setFollows(ev.tags, ev.content, ev.created_at);
|
||||||
}
|
}
|
||||||
if (ev?.kind === EventKind.Relays) {
|
|
||||||
Login.setRelays(ev.tags, ev.created_at);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
18
src/login.ts
18
src/login.ts
@ -2,8 +2,7 @@ import { bytesToHex } from "@noble/curves/abstract/utils";
|
|||||||
import { schnorr } from "@noble/curves/secp256k1";
|
import { schnorr } from "@noble/curves/secp256k1";
|
||||||
import { ExternalStore } from "@snort/shared";
|
import { ExternalStore } from "@snort/shared";
|
||||||
import { EventPublisher, Nip7Signer, PrivateKeySigner } from "@snort/system";
|
import { EventPublisher, Nip7Signer, PrivateKeySigner } from "@snort/system";
|
||||||
import type { EmojiPack, Relays } from "types";
|
import type { EmojiPack } from "types";
|
||||||
import { defaultRelays } from "const";
|
|
||||||
|
|
||||||
export enum LoginType {
|
export enum LoginType {
|
||||||
Nip7 = "nip7",
|
Nip7 = "nip7",
|
||||||
@ -23,7 +22,6 @@ export interface LoginSession {
|
|||||||
follows: ReplaceableTags;
|
follows: ReplaceableTags;
|
||||||
muted: ReplaceableTags;
|
muted: ReplaceableTags;
|
||||||
cards: ReplaceableTags;
|
cards: ReplaceableTags;
|
||||||
relays: Relays;
|
|
||||||
emojis: Array<EmojiPack>;
|
emojis: Array<EmojiPack>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +29,6 @@ const initialState = {
|
|||||||
follows: { tags: [], timestamp: 0 },
|
follows: { tags: [], timestamp: 0 },
|
||||||
muted: { tags: [], timestamp: 0 },
|
muted: { tags: [], timestamp: 0 },
|
||||||
cards: { tags: [], timestamp: 0 },
|
cards: { tags: [], timestamp: 0 },
|
||||||
relays: defaultRelays,
|
|
||||||
emojis: [],
|
emojis: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -113,19 +110,6 @@ export class LoginStore extends ExternalStore<LoginSession | undefined> {
|
|||||||
this.#save();
|
this.#save();
|
||||||
}
|
}
|
||||||
|
|
||||||
setRelays(relays: Array<string>, ts: number) {
|
|
||||||
if (this.#session.relays.timestamp >= ts) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.#session.relays = relays.reduce((acc, r) => {
|
|
||||||
const [, relay] = r;
|
|
||||||
const write = r.length === 2 || r.includes("write");
|
|
||||||
const read = r.length === 2 || r.includes("read");
|
|
||||||
return { ...acc, [relay]: { read, write } };
|
|
||||||
}, {});
|
|
||||||
this.#save();
|
|
||||||
}
|
|
||||||
|
|
||||||
#save() {
|
#save() {
|
||||||
if (this.#session) {
|
if (this.#session) {
|
||||||
window.localStorage.setItem(SESSION_KEY, JSON.stringify(this.#session));
|
window.localStorage.setItem(SESSION_KEY, JSON.stringify(this.#session));
|
||||||
|
Reference in New Issue
Block a user