mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
[EC-522] Improve handling of rxjs subjects (#3772)
* [EC-522] feat: no public rxjs subjects * [EC-522] feat: improve null handling * [EC-552] fix: init subject with empty set instead of null * [EC-552] fix: don't push null into account subject * [EC-522] feat: remove null filter
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { KdfType } from "../enums/kdfType";
|
||||
import { ThemeType } from "../enums/themeType";
|
||||
@@ -27,7 +27,7 @@ import { CollectionView } from "../models/view/collection.view";
|
||||
import { SendView } from "../models/view/send.view";
|
||||
|
||||
export abstract class StateService<T extends Account = Account> {
|
||||
accounts: BehaviorSubject<{ [userId: string]: T }>;
|
||||
accounts$: Observable<{ [userId: string]: T }>;
|
||||
activeAccount$: Observable<string>;
|
||||
activeAccountUnlocked$: Observable<boolean>;
|
||||
|
||||
|
||||
@@ -65,8 +65,10 @@ export class StateService<
|
||||
TAccount extends Account = Account
|
||||
> implements StateServiceAbstraction<TAccount>
|
||||
{
|
||||
accounts = new BehaviorSubject<{ [userId: string]: TAccount }>({});
|
||||
private activeAccountSubject = new BehaviorSubject<string>(null);
|
||||
private accountsSubject = new BehaviorSubject<{ [userId: string]: TAccount }>({});
|
||||
accounts$ = this.accountsSubject.asObservable();
|
||||
|
||||
private activeAccountSubject = new BehaviorSubject<string | null>(null);
|
||||
activeAccount$ = this.activeAccountSubject.asObservable();
|
||||
|
||||
private activeAccountUnlockedSubject = new BehaviorSubject<boolean>(false);
|
||||
@@ -2530,11 +2532,11 @@ export class StateService<
|
||||
await this.pruneInMemoryAccounts();
|
||||
await this.state().then((state) => {
|
||||
if (state.accounts == null || Object.keys(state.accounts).length < 1) {
|
||||
this.accounts.next(null);
|
||||
this.accountsSubject.next({});
|
||||
return;
|
||||
}
|
||||
|
||||
this.accounts.next(state.accounts);
|
||||
this.accountsSubject.next(state.accounts);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { AuthService } from "../abstractions/auth.service";
|
||||
import { MessagingService } from "../abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "../abstractions/platformUtils.service";
|
||||
@@ -19,7 +21,7 @@ export class SystemService implements SystemServiceAbstraction {
|
||||
) {}
|
||||
|
||||
async startProcessReload(authService: AuthService): Promise<void> {
|
||||
const accounts = this.stateService.accounts.getValue();
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
if (accounts != null) {
|
||||
const keys = Object.keys(accounts);
|
||||
if (keys.length > 0) {
|
||||
@@ -56,7 +58,7 @@ export class SystemService implements SystemServiceAbstraction {
|
||||
}
|
||||
|
||||
private async executeProcessReload() {
|
||||
const accounts = this.stateService.accounts.getValue();
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
const doRefresh =
|
||||
accounts == null ||
|
||||
Object.keys(accounts).length == 0 ||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { AuthService } from "../../abstractions/auth.service";
|
||||
import { CipherService } from "../../abstractions/cipher.service";
|
||||
import { CollectionService } from "../../abstractions/collection.service";
|
||||
@@ -52,7 +54,8 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const userId in this.stateService.accounts.getValue()) {
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
for (const userId in accounts) {
|
||||
if (userId != null && (await this.shouldLock(userId))) {
|
||||
await this.executeTimeoutAction(userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user