summaryrefslogtreecommitdiff
path: root/packages/frontend/src/preferences/manager.ts
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-03-14 15:43:56 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-03-14 15:43:56 +0900
commit0929410d3608da716e8e6c61f82f6f328a07d6bb (patch)
tree0d26f23689b5278b5fb810be62f16d62c709d55a /packages/frontend/src/preferences/manager.ts
parentBump version to 2025.3.2-beta.0 (diff)
downloadmisskey-0929410d3608da716e8e6c61f82f6f328a07d6bb.tar.gz
misskey-0929410d3608da716e8e6c61f82f6f328a07d6bb.tar.bz2
misskey-0929410d3608da716e8e6c61f82f6f328a07d6bb.zip
enhance(frontend): improve pref manager
Diffstat (limited to 'packages/frontend/src/preferences/manager.ts')
-rw-r--r--packages/frontend/src/preferences/manager.ts37
1 files changed, 27 insertions, 10 deletions
diff --git a/packages/frontend/src/preferences/manager.ts b/packages/frontend/src/preferences/manager.ts
index fad0226b6e..d72fa841ff 100644
--- a/packages/frontend/src/preferences/manager.ts
+++ b/packages/frontend/src/preferences/manager.ts
@@ -23,11 +23,10 @@ import { deepEqual } from '@/utility/deep-equal.js';
type PREF = typeof PREF_DEF;
type ValueOf<K extends keyof PREF> = PREF[K]['default'];
-type Account = string; // <host>/<userId>
type Scope = Partial<{
- server: string | null; // 将来のため
- account: Account | null;
+ server: string | null; // host
+ account: string | null; // userId
device: string | null; // 将来のため
}>;
@@ -39,7 +38,7 @@ type PrefRecord<K extends keyof PREF> = [scope: Scope, value: ValueOf<K>, meta:
function parseScope(scope: Scope): {
server: string | null;
- account: Account | null;
+ account: string | null;
device: string | null;
} {
return {
@@ -51,7 +50,7 @@ function parseScope(scope: Scope): {
function makeScope(scope: Partial<{
server: string | null;
- account: Account | null;
+ account: string | null;
device: string | null;
}>): Scope {
const c = {} as Scope;
@@ -130,6 +129,10 @@ export class PreferencesManager {
return (PREF_DEF as PreferencesDefinition)[key].accountDependent === true;
}
+ private isServerDependentKey<K extends keyof PREF>(key: K): boolean {
+ return (PREF_DEF as PreferencesDefinition)[key].serverDependent === true;
+ }
+
private rewriteRawState<K extends keyof PREF>(key: K, value: ValueOf<K>) {
const v = JSON.parse(JSON.stringify(value)); // deep copy 兼 vueのプロキシ解除
this.r[key].value = this.s[key] = v;
@@ -141,9 +144,19 @@ export class PreferencesManager {
this.rewriteRawState(key, value);
const record = this.getMatchedRecordOf(key);
+
if (parseScope(record[0]).account == null && this.isAccountDependentKey(key)) {
this.profile.preferences[key].push([makeScope({
- account: `${host}/${$i!.id}`,
+ server: host,
+ account: $i!.id,
+ }), value, {}]);
+ this.save();
+ return;
+ }
+
+ if (parseScope(record[0]).server == null && this.isServerDependentKey(key)) {
+ this.profile.preferences[key].push([makeScope({
+ server: host,
}), value, {}]);
this.save();
return;
@@ -291,16 +304,19 @@ export class PreferencesManager {
if ($i == null) return records.find(([scope, v]) => parseScope(scope).account == null)!;
- const accountOverrideRecord = records.find(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`);
+ const accountOverrideRecord = records.find(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id);
if (accountOverrideRecord) return accountOverrideRecord;
+ const serverOverrideRecord = records.find(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account == null);
+ if (serverOverrideRecord) return serverOverrideRecord;
+
const record = records.find(([scope, v]) => parseScope(scope).account == null);
return record!;
}
public isAccountOverrided<K extends keyof PREF>(key: K): boolean {
if ($i == null) return false;
- return this.profile.preferences[key].some(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`) ?? false;
+ return this.profile.preferences[key].some(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id) ?? false;
}
public setAccountOverride<K extends keyof PREF>(key: K) {
@@ -310,7 +326,8 @@ export class PreferencesManager {
const records = this.profile.preferences[key];
records.push([makeScope({
- account: `${host}/${$i!.id}`,
+ server: host,
+ account: $i!.id,
}), this.s[key], {}]);
this.save();
@@ -322,7 +339,7 @@ export class PreferencesManager {
const records = this.profile.preferences[key];
- const index = records.findIndex(([scope, v]) => parseScope(scope).account === `${host}/${$i!.id}`);
+ const index = records.findIndex(([scope, v]) => parseScope(scope).server === host && parseScope(scope).account === $i!.id);
if (index === -1) return;
records.splice(index, 1);