mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +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:
@@ -38,7 +38,7 @@ describe("browserSession decorator", () => {
|
||||
@browserSession
|
||||
class TestClass {
|
||||
@sessionSync({ initializer: (s: string) => s })
|
||||
behaviorSubject = new BehaviorSubject("");
|
||||
private behaviorSubject = new BehaviorSubject("");
|
||||
|
||||
constructor(private stateService: StateService) {}
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ describe("sessionSync decorator", () => {
|
||||
const ctor = String;
|
||||
class TestClass {
|
||||
@sessionSync({ ctor: ctor, initializer: initializer })
|
||||
testProperty = new BehaviorSubject("");
|
||||
private testProperty = new BehaviorSubject("");
|
||||
|
||||
complete() {
|
||||
this.testProperty.complete();
|
||||
}
|
||||
}
|
||||
|
||||
it("should add __syncedItemKeys to prototype", () => {
|
||||
@@ -19,7 +23,7 @@ describe("sessionSync decorator", () => {
|
||||
ctor: ctor,
|
||||
initializer: initializer,
|
||||
}),
|
||||
testClass.testProperty.complete(),
|
||||
testClass.complete(),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,12 +54,12 @@ export class VaultSelectComponent implements OnInit, OnDestroy {
|
||||
buttonRef: ElementRef<HTMLButtonElement>;
|
||||
@ViewChild("vaultSelectorTemplate", { read: TemplateRef }) templateRef: TemplateRef<HTMLElement>;
|
||||
|
||||
private _selectedVault = new BehaviorSubject<string>(null);
|
||||
private _selectedVault = new BehaviorSubject<string | null>(null);
|
||||
|
||||
isOpen = false;
|
||||
loaded = false;
|
||||
organizations$: Observable<Organization[]>;
|
||||
selectedVault$: Observable<string> = this._selectedVault.asObservable();
|
||||
selectedVault$: Observable<string | null> = this._selectedVault.asObservable();
|
||||
|
||||
vaultFilter: VaultFilter = new VaultFilter();
|
||||
enforcePersonalOwnership = false;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { DomSanitizer } from "@angular/platform-browser";
|
||||
import { Router } from "@angular/router";
|
||||
import { IndividualConfig, ToastrService } from "ngx-toastr";
|
||||
import { Subject, takeUntil } from "rxjs";
|
||||
import { firstValueFrom, Subject, takeUntil } from "rxjs";
|
||||
|
||||
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
|
||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||
@@ -175,7 +175,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
await this.vaultTimeoutService.lock(message.userId);
|
||||
break;
|
||||
case "lockAllVaults":
|
||||
for (const userId in this.stateService.accounts.getValue()) {
|
||||
for (const userId in await firstValueFrom(this.stateService.accounts$)) {
|
||||
if (userId != null) {
|
||||
await this.vaultTimeoutService.lock(userId);
|
||||
}
|
||||
@@ -429,7 +429,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
private async updateAppMenu() {
|
||||
let updateRequest: MenuUpdateRequest;
|
||||
const stateAccounts = this.stateService.accounts?.getValue();
|
||||
const stateAccounts = await firstValueFrom(this.stateService.accounts$);
|
||||
if (stateAccounts == null || Object.keys(stateAccounts).length < 1) {
|
||||
updateRequest = {
|
||||
accounts: null,
|
||||
@@ -593,7 +593,8 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private async checkForSystemTimeout(timeout: number): Promise<void> {
|
||||
for (const userId in this.stateService.accounts.getValue()) {
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
for (const userId in accounts) {
|
||||
if (userId == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { CanActivate } from "@angular/router";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
||||
@@ -17,7 +18,7 @@ export class LoginGuard implements CanActivate {
|
||||
) {}
|
||||
|
||||
async canActivate() {
|
||||
const accounts = this.stateService.accounts.getValue();
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
if (accounts != null && Object.keys(accounts).length >= maxAllowedAccounts) {
|
||||
this.platformUtilsService.showToast("error", null, this.i18nService.t("accountLimitReached"));
|
||||
return false;
|
||||
|
||||
@@ -97,7 +97,7 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy {
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.stateService.accounts
|
||||
this.stateService.accounts$
|
||||
.pipe(
|
||||
concatMap(async (accounts: { [userId: string]: Account }) => {
|
||||
for (const userId in accounts) {
|
||||
|
||||
@@ -8,7 +8,7 @@ export type SearchBarState = {
|
||||
|
||||
@Injectable()
|
||||
export class SearchBarService {
|
||||
private searchTextSubject = new BehaviorSubject<string>(null);
|
||||
private searchTextSubject = new BehaviorSubject<string | null>(null);
|
||||
searchText$ = this.searchTextSubject.asObservable();
|
||||
|
||||
private _state = {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
||||
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
||||
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
||||
@@ -78,7 +80,7 @@ export class EncryptedMessageHandlerService {
|
||||
}
|
||||
|
||||
private async statusCommandHandler(): Promise<AccountStatusResponse[]> {
|
||||
const accounts = this.stateService.accounts.getValue();
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
const activeUserId = await this.stateService.getUserId();
|
||||
|
||||
if (!accounts || !Object.keys(accounts)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
import Swal from "sweetalert2";
|
||||
|
||||
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
||||
@@ -58,7 +59,8 @@ export class NativeMessagingService {
|
||||
const remotePublicKey = Utils.fromB64ToArray(rawMessage.publicKey).buffer;
|
||||
|
||||
// Validate the UserId to ensure we are logged into the same account.
|
||||
const userIds = Object.keys(this.stateService.accounts.getValue());
|
||||
const accounts = await firstValueFrom(this.stateService.accounts$);
|
||||
const userIds = Object.keys(accounts);
|
||||
if (!userIds.includes(rawMessage.userId)) {
|
||||
ipcRenderer.send("nativeMessagingReply", { command: "wrongUserId", appId: appId });
|
||||
return;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
|
||||
@Injectable()
|
||||
export class VaultFilterService extends BaseVaultFilterService {
|
||||
private _collapsedFilterNodes = new BehaviorSubject<Set<string>>(null);
|
||||
private _collapsedFilterNodes = new BehaviorSubject<Set<string>>(new Set());
|
||||
collapsedFilterNodes$: Observable<Set<string>> = this._collapsedFilterNodes.asObservable();
|
||||
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user