summaryrefslogtreecommitdiff
path: root/packages/client/src
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2021-12-30 00:34:23 +0900
committertamaina <tamaina@hotmail.co.jp>2021-12-30 00:34:23 +0900
commit41a7ab50240b1a4a1baeb0fa935530be012fa3c8 (patch)
treee66a5d2125e8fa81d2681e8bccf2949b17b7920c /packages/client/src
parentwip (diff)
downloadmisskey-41a7ab50240b1a4a1baeb0fa935530be012fa3c8.tar.gz
misskey-41a7ab50240b1a4a1baeb0fa935530be012fa3c8.tar.bz2
misskey-41a7ab50240b1a4a1baeb0fa935530be012fa3c8.zip
migrate
Diffstat (limited to 'packages/client/src')
-rw-r--r--packages/client/src/pizzax.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts
index 1ebff07fa7..3ac4c5c720 100644
--- a/packages/client/src/pizzax.ts
+++ b/packages/client/src/pizzax.ts
@@ -30,6 +30,7 @@ export class Storage<T extends StateDef> {
public readonly state = {} as State<T>;
public readonly reactiveState = {} as ReactiveState<T>;
+ // indexedDB保存を重複させないために簡易的にキューイング
private nextIdbJob: Promise<any> = Promise.resolve();
private addIdbSetJob<T>(job: () => Promise<T>) {
const promise = this.nextIdbJob.then(job, e => {
@@ -52,6 +53,8 @@ export class Storage<T extends StateDef> {
private init(): Promise<void> {
return new Promise(async (resolve, reject) => {
+ await this.migrate();
+
const deviceState: State<T> = await get(this.deviceStateKeyName);
const deviceAccountState = $i ? await get(this.deviceAccountStateKeyName) : {};
const registryCache = $i ? await get(this.registryCacheKeyName) : {};
@@ -95,6 +98,7 @@ export class Storage<T extends StateDef> {
})
.then(() => resolve());
}, 1);
+
// streamingのuser storage updateイベントを監視して更新
connection?.on('registryUpdated', async ({ scope, key, value }: { scope: string[], key: keyof T, value: T[typeof key]['default'] }) => {
if (scope[1] !== this.key || this.state[key] === value) return;
@@ -190,4 +194,25 @@ export class Storage<T extends StateDef> {
}
};
}
+
+ // localStorage => indexedDBのマイグレーション
+ private async migrate() {
+ const deviceState = localStorage.getItem(this.deviceStateKeyName);
+ if (deviceState) {
+ await set(this.deviceStateKeyName, JSON.parse(deviceState));
+ localStorage.removeItem(this.deviceStateKeyName);
+ }
+
+ const deviceAccountState = $i && localStorage.getItem(this.deviceAccountStateKeyName);
+ if ($i && deviceAccountState) {
+ await set(this.deviceAccountStateKeyName, JSON.parse(deviceAccountState));
+ localStorage.removeItem(this.deviceAccountStateKeyName);
+ }
+
+ const registryCache = $i && localStorage.getItem(this.registryCacheKeyName);
+ if ($i && registryCache) {
+ await set(this.registryCacheKeyName, JSON.parse(registryCache));
+ localStorage.removeItem(this.registryCacheKeyName);
+ }
+ }
}