[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;
|
everBeenUnlocked?: boolean;
|
||||||
forcePasswordReset?: boolean;
|
forcePasswordReset?: boolean;
|
||||||
hasPremiumPersonally?: boolean;
|
hasPremiumPersonally?: boolean;
|
||||||
lastActive?: number;
|
|
||||||
lastSync?: string;
|
lastSync?: string;
|
||||||
userId?: string;
|
userId?: string;
|
||||||
usesKeyConnector?: boolean;
|
usesKeyConnector?: boolean;
|
||||||
|
|
|
@ -9,6 +9,7 @@ export class State<
|
||||||
globals: TGlobalState;
|
globals: TGlobalState;
|
||||||
activeUserId: string;
|
activeUserId: string;
|
||||||
authenticatedAccounts: string[] = [];
|
authenticatedAccounts: string[] = [];
|
||||||
|
accountActivity: { [userId: string]: number } = {};
|
||||||
|
|
||||||
constructor(globals: TGlobalState) {
|
constructor(globals: TGlobalState) {
|
||||||
this.globals = globals;
|
this.globals = globals;
|
||||||
|
|
|
@ -46,6 +46,7 @@ const keys = {
|
||||||
authenticatedAccounts: "authenticatedAccounts",
|
authenticatedAccounts: "authenticatedAccounts",
|
||||||
activeUserId: "activeUserId",
|
activeUserId: "activeUserId",
|
||||||
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
||||||
|
accountActivity: "accountActivity",
|
||||||
};
|
};
|
||||||
|
|
||||||
const partialKeys = {
|
const partialKeys = {
|
||||||
|
@ -117,7 +118,7 @@ export class StateService<
|
||||||
async addAccount(account: TAccount) {
|
async addAccount(account: TAccount) {
|
||||||
account = await this.setAccountEnvironmentUrls(account);
|
account = await this.setAccountEnvironmentUrls(account);
|
||||||
this.state.authenticatedAccounts.push(account.profile.userId);
|
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;
|
this.state.accounts[account.profile.userId] = account;
|
||||||
await this.scaffoldNewAccountStorage(account);
|
await this.scaffoldNewAccountStorage(account);
|
||||||
await this.setActiveUser(account.profile.userId);
|
await this.setActiveUser(account.profile.userId);
|
||||||
|
@ -1561,22 +1562,32 @@ export class StateService<
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLastActive(options?: StorageOptions): Promise<number> {
|
async getLastActive(options?: StorageOptions): Promise<number> {
|
||||||
return (
|
options = this.reconcileOptions(options, await this.defaultOnDiskOptions());
|
||||||
await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions()))
|
|
||||||
)?.profile?.lastActive;
|
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> {
|
async setLastActive(value: number, options?: StorageOptions): Promise<void> {
|
||||||
const account = await this.getAccount(
|
options = this.reconcileOptions(options, await this.defaultOnDiskOptions());
|
||||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
if (options.userId == null) {
|
||||||
);
|
return;
|
||||||
if (account != null) {
|
|
||||||
account.profile.lastActive = value;
|
|
||||||
await this.saveAccount(
|
|
||||||
account,
|
|
||||||
this.reconcileOptions(options, await this.defaultOnDiskOptions())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
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> {
|
async getLastSync(options?: StorageOptions): Promise<string> {
|
||||||
|
|
|
@ -122,6 +122,7 @@ const keys = {
|
||||||
authenticatedAccounts: "authenticatedAccounts",
|
authenticatedAccounts: "authenticatedAccounts",
|
||||||
activeUserId: "activeUserId",
|
activeUserId: "activeUserId",
|
||||||
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
tempAccountSettings: "tempAccountSettings", // used to hold account specific settings (i.e clear clipboard) between initial migration and first account authentication
|
||||||
|
accountActivity: "accountActivity",
|
||||||
};
|
};
|
||||||
|
|
||||||
const partialKeys = {
|
const partialKeys = {
|
||||||
|
@ -396,7 +397,6 @@ export class StateMigrationService<
|
||||||
kdfIterations: await this.get<number>(v1Keys.kdfIterations),
|
kdfIterations: await this.get<number>(v1Keys.kdfIterations),
|
||||||
kdfType: await this.get<KdfType>(v1Keys.kdf),
|
kdfType: await this.get<KdfType>(v1Keys.kdf),
|
||||||
keyHash: await this.get<string>(v1Keys.keyHash),
|
keyHash: await this.get<string>(v1Keys.keyHash),
|
||||||
lastActive: await this.get<number>(v1Keys.lastActive),
|
|
||||||
lastSync: null,
|
lastSync: null,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
usesKeyConnector: null,
|
usesKeyConnector: null,
|
||||||
|
@ -412,6 +412,13 @@ export class StateMigrationService<
|
||||||
|
|
||||||
await this.set(keys.authenticatedAccounts, [userId]);
|
await this.set(keys.authenticatedAccounts, [userId]);
|
||||||
await this.set(keys.activeUserId, 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);
|
await clearV1Keys(userId);
|
||||||
|
|
||||||
if (await this.secureStorageService.has(v1Keys.key, { keySuffix: "biometric" })) {
|
if (await this.secureStorageService.has(v1Keys.key, { keySuffix: "biometric" })) {
|
||||||
|
|
Loading…
Reference in New Issue