import { SettingsService as SettingsServiceAbstraction } from "../abstractions/settings.service" ; import { StateService } from "../abstractions/state.service" ; const Keys = { settingsPrefix : "settings_" , equivalentDomains : "equivalentDomains" , } ; export class SettingsService implements SettingsServiceAbstraction { constructor ( private stateService ) { } async clearCache ( ) { await this . stateService . setSettings ( null ) ; } getEquivalentDomains ( ) { return this . getSettingsKey ( Keys . equivalentDomains ) ; } async setEquivalentDomains ( equivalentDomains ) { await this . setSettingsKey ( Keys . equivalentDomains , equivalentDomains ) ; } async clear ( userId ? ) { await this . stateService . setSettings ( null , { userId : userId } ) ; } private async getSettings ( ) { const settings = await this . stateService . getSettings ( ) ; if ( settings == null ) { const userId = await this . stateService . getUserId ( ) ; } return settings ; } private async getSettingsKey ( key ) { const settings = await this . getSettings ( ) ; if ( settings != null && settings [ key ] ) { return settings [ key ] ; } return null ; } private async setSettingsKey ( key , value ) { let settings = await this . getSettings ( ) ; if ( ! settings ) { settings = { } ; } settings [ key ] = value ; await this . stateService . setSettings ( settings ) ; } }