mirror of
https://github.com/bitwarden/browser
synced 2026-01-05 01:53:55 +00:00
* [EC-381] Deleted unused method clearCache from Settings Service
* [EC-381] Marked settings methods as obsolete on State service
* [EC-381] Using observables on settings service
* [EC-381] Added unit tests for Settings service
* [EC-381] Checking userId on clear
* [EC-381] Updated references to StateService activeAccountUnlocked$
* [EC-381] Updated getEquivalentDomains to return observable
* [EC-381] Updated settings service to user concatMap on activeAccountUnlocked$
* [EC-381] Renamed getEquivalentDomains to equivalentDomains
* [EC-381] Completing Behaviors on settings.service tests
* [EC-381] Removed unused settingsPrefix from settings service
* [EC-381] Removed equivalentDomains from settings service and added type AccountSettingsSettings
* [EC-381] Updated settings service settings$ to not be nullable
* [EC-381] Settings default to {}
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { BehaviorSubject, concatMap } from "rxjs";
|
|
|
|
import { SettingsService as SettingsServiceAbstraction } from "../abstractions/settings.service";
|
|
import { StateService } from "../abstractions/state.service";
|
|
import { Utils } from "../misc/utils";
|
|
import { AccountSettingsSettings } from "../models/domain/account";
|
|
|
|
export class SettingsService implements SettingsServiceAbstraction {
|
|
private _settings: BehaviorSubject<AccountSettingsSettings> = new BehaviorSubject({});
|
|
|
|
settings$ = this._settings.asObservable();
|
|
|
|
constructor(private stateService: StateService) {
|
|
this.stateService.activeAccountUnlocked$
|
|
.pipe(
|
|
concatMap(async (unlocked) => {
|
|
if (Utils.global.bitwardenContainerService == null) {
|
|
return;
|
|
}
|
|
|
|
if (!unlocked) {
|
|
this._settings.next({});
|
|
return;
|
|
}
|
|
|
|
const data = await this.stateService.getSettings();
|
|
|
|
this._settings.next(data);
|
|
})
|
|
)
|
|
.subscribe();
|
|
}
|
|
|
|
async setEquivalentDomains(equivalentDomains: string[][]): Promise<void> {
|
|
const settings = this._settings.getValue() ?? {};
|
|
|
|
settings.equivalentDomains = equivalentDomains;
|
|
|
|
this._settings.next(settings);
|
|
await this.stateService.setSettings(settings);
|
|
}
|
|
|
|
async clear(userId?: string): Promise<void> {
|
|
if (userId == null || userId == (await this.stateService.getUserId())) {
|
|
this._settings.next({});
|
|
}
|
|
|
|
await this.stateService.setSettings(null, { userId: userId });
|
|
}
|
|
}
|