[bug] Make activity a top level storage key (#656)
* [bug] Make activity a top level storage key * [bug] use correct index for migration * [bug] use correct index for migration part 2
This commit is contained in:
parent
0760b53296
commit
6c08b40847
|
@ -94,7 +94,6 @@ export class AccountProfile {
|
|||
everBeenUnlocked?: boolean;
|
||||
forcePasswordReset?: boolean;
|
||||
hasPremiumPersonally?: boolean;
|
||||
lastActive?: number;
|
||||
lastSync?: string;
|
||||
userId?: string;
|
||||
usesKeyConnector?: boolean;
|
||||
|
|
|
@ -9,6 +9,7 @@ export class State<
|
|||
globals: TGlobalState;
|
||||
activeUserId: string;
|
||||
authenticatedAccounts: string[] = [];
|
||||
accountActivity: { [userId: string]: number } = {};
|
||||
|
||||
constructor(globals: TGlobalState) {
|
||||
this.globals = globals;
|
||||
|
|
|
@ -46,6 +46,7 @@ const keys = {
|
|||
authenticatedAccounts: "authenticatedAccounts",
|
||||
activeUserId: "activeUserId",
|
||||
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
||||
accountActivity: "accountActivity",
|
||||
};
|
||||
|
||||
const partialKeys = {
|
||||
|
@ -117,7 +118,7 @@ export class StateService<
|
|||
async addAccount(account: TAccount) {
|
||||
account = await this.setAccountEnvironmentUrls(account);
|
||||
this.state.authenticatedAccounts.push(account.profile.userId);
|
||||
this.storageService.save(keys.authenticatedAccounts, this.state.authenticatedAccounts);
|
||||
await this.storageService.save(keys.authenticatedAccounts, this.state.authenticatedAccounts);
|
||||
this.state.accounts[account.profile.userId] = account;
|
||||
await this.scaffoldNewAccountStorage(account);
|
||||
await this.setActiveUser(account.profile.userId);
|
||||
|
@ -1561,22 +1562,32 @@ export class StateService<
|
|||
}
|
||||
|
||||
async getLastActive(options?: StorageOptions): Promise<number> {
|
||||
return (
|
||||
await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions()))
|
||||
)?.profile?.lastActive;
|
||||
options = this.reconcileOptions(options, await this.defaultOnDiskOptions());
|
||||
|
||||
const accountActivity = await this.storageService.get<{ [userId: string]: number }>(
|
||||
keys.accountActivity,
|
||||
options
|
||||
);
|
||||
|
||||
if (accountActivity == null || Object.keys(accountActivity).length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return accountActivity[options.userId];
|
||||
}
|
||||
|
||||
async setLastActive(value: number, options?: StorageOptions): Promise<void> {
|
||||
const account = await this.getAccount(
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
if (account != null) {
|
||||
account.profile.lastActive = value;
|
||||
await this.saveAccount(
|
||||
account,
|
||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
||||
);
|
||||
options = this.reconcileOptions(options, await this.defaultOnDiskOptions());
|
||||
if (options.userId == null) {
|
||||
return;
|
||||
}
|
||||
const accountActivity =
|
||||
(await this.storageService.get<{ [userId: string]: number }>(
|
||||
keys.accountActivity,
|
||||
options
|
||||
)) ?? {};
|
||||
accountActivity[options.userId] = value;
|
||||
await this.storageService.save(keys.accountActivity, accountActivity, options);
|
||||
}
|
||||
|
||||
async getLastSync(options?: StorageOptions): Promise<string> {
|
||||
|
|
|
@ -122,6 +122,7 @@ const keys = {
|
|||
authenticatedAccounts: "authenticatedAccounts",
|
||||
activeUserId: "activeUserId",
|
||||
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
||||
accountActivity: "accountActivity",
|
||||
};
|
||||
|
||||
const partialKeys = {
|
||||
|
@ -396,7 +397,6 @@ export class StateMigrationService<
|
|||
kdfIterations: await this.get<number>(v1Keys.kdfIterations),
|
||||
kdfType: await this.get<KdfType>(v1Keys.kdf),
|
||||
keyHash: await this.get<string>(v1Keys.keyHash),
|
||||
lastActive: await this.get<number>(v1Keys.lastActive),
|
||||
lastSync: null,
|
||||
userId: userId,
|
||||
usesKeyConnector: null,
|
||||
|
@ -412,6 +412,13 @@ export class StateMigrationService<
|
|||
|
||||
await this.set(keys.authenticatedAccounts, [userId]);
|
||||
await this.set(keys.activeUserId, userId);
|
||||
|
||||
const accountActivity: { [userId: string]: number } = {
|
||||
[userId]: await this.get<number>(v1Keys.lastActive),
|
||||
};
|
||||
accountActivity[userId] = await this.get<number>(v1Keys.lastActive);
|
||||
await this.set(keys.accountActivity, accountActivity);
|
||||
|
||||
await clearV1Keys(userId);
|
||||
|
||||
if (await this.secureStorageService.has(v1Keys.key, { keySuffix: "biometric" })) {
|
||||
|
|
Loading…
Reference in New Issue