From a6092916d80424b8bf4d34e321a0b58f15c7519d Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Tue, 15 Feb 2022 12:54:22 -0500 Subject: [PATCH] [bug] Persistantly store collapsedGroupings (#686) Collapsed groupings have regressed to not maintaining their state through restarting clients. The state mangement refactor erroniously began saving this field to memory instead of disk, but there were some other issues that changing this brought on that are also fixed in this commit. Changes: 1. Save collapsedGroupings persistantly in StateService 2. Adjust the type of collapsedGroupings on the Account model from a Set to a string[] * This is the way we were storing this value in previous releases, and saving the entire set object breaks. 3. Adjust the StateService getter/setter for collapsedGroupings to expect a string[] 4. Extract a string[] from the GroupingsComponent groupings that is a Set before saving --- angular/src/components/groupings.component.ts | 2 +- common/src/abstractions/state.service.ts | 4 ++-- common/src/models/domain/account.ts | 2 +- common/src/services/state.service.ts | 16 ++++++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/angular/src/components/groupings.component.ts b/angular/src/components/groupings.component.ts index e8a97c6fd2..4176e291bc 100644 --- a/angular/src/components/groupings.component.ts +++ b/angular/src/components/groupings.component.ts @@ -151,7 +151,7 @@ export class GroupingsComponent { } else { this.collapsedGroupings.add(id); } - await this.stateService.setCollapsedGroupings(this.collapsedGroupings); + await this.stateService.setCollapsedGroupings(Array.from(this.collapsedGroupings)); } isCollapsed(grouping: FolderView | CollectionView, idPrefix = "") { diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index e4c38025a4..49d3e2f67f 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -63,8 +63,8 @@ export abstract class StateService { getCanAccessPremium: (options?: StorageOptions) => Promise; getClearClipboard: (options?: StorageOptions) => Promise; setClearClipboard: (value: number, options?: StorageOptions) => Promise; - getCollapsedGroupings: (options?: StorageOptions) => Promise>; - setCollapsedGroupings: (value: Set, options?: StorageOptions) => Promise; + getCollapsedGroupings: (options?: StorageOptions) => Promise; + setCollapsedGroupings: (value: string[], options?: StorageOptions) => Promise; getConvertAccountToKeyConnector: (options?: StorageOptions) => Promise; setConvertAccountToKeyConnector: (value: boolean, options?: StorageOptions) => Promise; getCryptoMasterKey: (options?: StorageOptions) => Promise; diff --git a/common/src/models/domain/account.ts b/common/src/models/domain/account.ts index 012ce09cd7..5c0337e5d4 100644 --- a/common/src/models/domain/account.ts +++ b/common/src/models/domain/account.ts @@ -54,7 +54,7 @@ export class AccountData { GeneratedPasswordHistory[] > = new EncryptionPair(); addEditCipherInfo?: any; - collapsedGroupings?: Set; + collapsedGroupings?: string[]; eventCollection?: EventData[]; organizations?: { [id: string]: OrganizationData }; providers?: { [id: string]: ProviderData }; diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index da7fb97aa2..30f908f761 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -388,17 +388,21 @@ export class StateService< ); } - async getCollapsedGroupings(options?: StorageOptions): Promise> { - return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions))) - ?.data?.collapsedGroupings; + async getCollapsedGroupings(options?: StorageOptions): Promise { + return ( + await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) + )?.data?.collapsedGroupings; } - async setCollapsedGroupings(value: Set, options?: StorageOptions): Promise { + async setCollapsedGroupings(value: string[], options?: StorageOptions): Promise { const account = await this.getAccount( - this.reconcileOptions(options, this.defaultInMemoryOptions) + this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()) ); account.data.collapsedGroupings = value; - await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions)); + await this.saveAccount( + account, + this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()) + ); } async getConvertAccountToKeyConnector(options?: StorageOptions): Promise {