feat: account switching

This commit is contained in:
2023-04-19 13:10:41 +01:00
parent 9dacad430a
commit e5b215abb5
19 changed files with 310 additions and 400 deletions

View File

@ -73,6 +73,17 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
return [...this.#accounts.keys()];
}
allSubscriptions() {
return [...this.#accounts.values()].map(a => a.subscriptions).flat();
}
switchAccount(pk: string) {
if (this.#accounts.has(pk)) {
this.#activeAccount = pk;
this.#save();
}
}
loginWithPubkey(key: HexKey, relays?: Record<string, RelaySettings>) {
if (this.#accounts.has(key)) {
throw new Error("Already logged in with this pubkey");
@ -127,6 +138,9 @@ export class MultiAccountStore extends ExternalStore<LoginSession> {
removeSession(k: string) {
if (this.#accounts.delete(k)) {
if (this.#activeAccount === k) {
this.#activeAccount = undefined;
}
this.#save();
}
}