fix: follow graph / readonly login
This commit is contained in:
parent
778ce1a24f
commit
6398e470ef
@ -29,7 +29,7 @@ export class EventCacheWorker extends EventEmitter<CacheEvents> implements Cache
|
||||
"REQ",
|
||||
"events-search",
|
||||
{
|
||||
search: q
|
||||
search: q,
|
||||
},
|
||||
]);
|
||||
return results;
|
||||
|
@ -35,7 +35,7 @@ export class ProfileCacheRelayWorker extends EventEmitter<CacheEvents> implement
|
||||
"profiles-search",
|
||||
{
|
||||
kinds: [0],
|
||||
search: q
|
||||
search: q,
|
||||
},
|
||||
]);
|
||||
return removeUndefined(profiles.map(mapEventToProfile));
|
||||
|
@ -35,7 +35,7 @@ export class UserFollowsWorker extends EventEmitter<CacheEvents> implements Cach
|
||||
"contacts-search",
|
||||
{
|
||||
kinds: [3],
|
||||
search: q
|
||||
search: q,
|
||||
},
|
||||
]);
|
||||
return removeUndefined(results.map(mapEventToUserFollows));
|
||||
|
@ -24,10 +24,9 @@ export default function useLoginFeed() {
|
||||
}, [system, checkSigs]);
|
||||
|
||||
useEffect(() => {
|
||||
if (publisher) {
|
||||
login.state.init(publisher.signer, system).catch(console.error);
|
||||
}
|
||||
login.state.init(publisher?.signer, system).catch(console.error);
|
||||
}, [login, publisher, system]);
|
||||
|
||||
const subLogin = useMemo(() => {
|
||||
if (!login || !pubKey) return null;
|
||||
|
||||
@ -44,7 +43,6 @@ export default function useLoginFeed() {
|
||||
.limit(10);
|
||||
return b;
|
||||
}
|
||||
|
||||
}, [pubKey, login]);
|
||||
|
||||
const loginFeed = useRequestBuilder(subLogin);
|
||||
|
@ -113,6 +113,12 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
|
||||
);
|
||||
stateClass.on("change", () => this.#save());
|
||||
v.state = stateClass;
|
||||
|
||||
// always activate signer
|
||||
const signer = createPublisher(v);
|
||||
if (signer) {
|
||||
this.#publishers.set(v.id, signer);
|
||||
}
|
||||
}
|
||||
this.#loadIrisKeyIfExists();
|
||||
}
|
||||
@ -194,7 +200,7 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
|
||||
newSession.state.on("change", () => this.#save());
|
||||
const pub = createPublisher(newSession);
|
||||
if (pub) {
|
||||
this.setPublisher(newSession.id, pub);
|
||||
this.#publishers.set(newSession.id, pub);
|
||||
}
|
||||
this.#accounts.set(newSession.id, newSession);
|
||||
this.#activeAccount = newSession.id;
|
||||
@ -248,7 +254,7 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
|
||||
newSession.privateKeyData = undefined;
|
||||
}
|
||||
const pub = EventPublisher.privateKey(key.value);
|
||||
this.setPublisher(newSession.id, pub);
|
||||
this.#publishers.set(newSession.id, pub);
|
||||
|
||||
this.#accounts.set(newSession.id, newSession);
|
||||
this.#activeAccount = newSession.id;
|
||||
|
@ -1,5 +1,14 @@
|
||||
import { dedupe, ExternalStore } from "@snort/shared";
|
||||
import { decodeTLV, encodeTLVEntries, EventKind, NostrEvent, NostrPrefix, RequestBuilder, TLVEntry, TLVEntryType } from "@snort/system";
|
||||
import {
|
||||
decodeTLV,
|
||||
encodeTLVEntries,
|
||||
EventKind,
|
||||
NostrEvent,
|
||||
NostrPrefix,
|
||||
RequestBuilder,
|
||||
TLVEntry,
|
||||
TLVEntryType,
|
||||
} from "@snort/system";
|
||||
|
||||
import { GiftsCache } from "@/Cache";
|
||||
import { GiftWrapCache } from "@/Cache/GiftWrapCache";
|
||||
@ -127,4 +136,4 @@ export class Nip17ChatSystem extends ExternalStore<Array<Chat>> implements ChatS
|
||||
}
|
||||
}
|
||||
|
||||
export const Nip17Chats = new Nip17ChatSystem(GiftsCache);
|
||||
export const Nip17Chats = new Nip17ChatSystem(GiftsCache);
|
||||
|
@ -54,13 +54,11 @@ async function initSite() {
|
||||
setupWebLNWalletConfig(Wallets);
|
||||
|
||||
db.ready = await db.isAvailable();
|
||||
if (db.ready) {
|
||||
const login = LoginStore.snapshot();
|
||||
preload(login.state.follows); // dont await this
|
||||
System.PreloadSocialGraph(); // dont await this
|
||||
}
|
||||
|
||||
queueMicrotask(() => {
|
||||
const login = LoginStore.snapshot();
|
||||
preload(login.state.follows).then(async () => {
|
||||
await System.PreloadSocialGraph();
|
||||
|
||||
for (const ev of UserCache.snapshot()) {
|
||||
try {
|
||||
addCachedMetadataToFuzzySearch(ev);
|
||||
|
@ -10,7 +10,7 @@ declare interface Nip44Window {
|
||||
encrypt(recipientHexPubKey: string, value: string): Promise<string>;
|
||||
decrypt(senderHexPubKey: string, value: string): Promise<string>;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export class Nip7Signer implements EventSigner {
|
||||
|
@ -99,10 +99,10 @@ export class DiffSyncTags extends EventEmitter<SafeSyncEvents> {
|
||||
this.emit("change");
|
||||
}
|
||||
|
||||
async sync(signer: EventSigner, system: SystemInterface) {
|
||||
async sync(signer: EventSigner | undefined, system: SystemInterface) {
|
||||
await this.#sync.sync(system);
|
||||
|
||||
if (this.#sync.value?.content && this.contentEncrypted) {
|
||||
if (this.#sync.value?.content && this.contentEncrypted && signer) {
|
||||
const decrypted = await signer.nip4Decrypt(this.#sync.value.content, await signer.getPubKey());
|
||||
this.#decryptedContent = decrypted;
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ export class JsonEventSync<T> extends EventEmitter<SafeSyncEvents> {
|
||||
return Object.freeze(ret);
|
||||
}
|
||||
|
||||
async sync(signer: EventSigner, system: SystemInterface) {
|
||||
async sync(signer: EventSigner | undefined, system: SystemInterface) {
|
||||
const res = await this.#sync.sync(system);
|
||||
this.#log("Sync result %O", res);
|
||||
if (res) {
|
||||
if (this.encrypt) {
|
||||
if (!signer) return;
|
||||
this.#json = JSON.parse(await signer.nip4Decrypt(res.content, await signer.getPubKey())) as T;
|
||||
} else {
|
||||
this.#json = JSON.parse(res.content) as T;
|
||||
|
@ -94,7 +94,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
this.#relays.on("change", () => this.emit("change", UserStateChangeType.Relays));
|
||||
}
|
||||
|
||||
async init(signer: EventSigner, system: SystemInterface) {
|
||||
async init(signer: EventSigner | undefined, system: SystemInterface) {
|
||||
if (this.#didInit) {
|
||||
return;
|
||||
}
|
||||
@ -124,7 +124,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
);
|
||||
|
||||
// update relay metadata with value from contact list if not found
|
||||
if (this.#relays.value === undefined && this.#contacts.value?.content !== undefined) {
|
||||
if (this.#relays.value === undefined && this.#contacts.value?.content !== undefined && signer) {
|
||||
this.#log("Saving relays to NIP-65 relay list using %O", this.relays);
|
||||
for (const r of this.relays ?? []) {
|
||||
await this.addRelay(r.url, r.settings, false);
|
||||
@ -135,7 +135,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
||||
|
||||
// migrate mutes into blocks
|
||||
const muteList = this.#standardLists.get(EventKind.MuteList);
|
||||
if (muteList && muteList.tags.length > 0) {
|
||||
if (muteList && muteList.tags.length > 0 && signer) {
|
||||
this.#log("Migrating mutes into blocks mutes=%i, blocks=%i", muteList.tags.length, muteList.encryptedTags.length);
|
||||
muteList.replace([], false);
|
||||
muteList.add(muteList!.tags, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user