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