1
0
Fork 0
mirror of https://github.com/paricafe/misskey.git synced 2025-03-23 11:39:25 -05:00
This commit is contained in:
syuilo 2025-03-12 15:07:45 +09:00
parent e594fb0037
commit 8508c4dadc
2 changed files with 38 additions and 19 deletions
packages/frontend/src

View file

@ -87,6 +87,21 @@ const storageProvider: StorageProvider = {
value: cloudData,
});
},
cloudGets: async (ctx) => {
// TODO: 値の取得を1つのリクエストで済ませたい(バックエンド側でAPIの新設が必要)
const fetchings = ctx.needs.map(need => storageProvider.cloudGet(need).then(res => [need.key, res] as const));
const cloudDatas = await Promise.all(fetchings);
const res = {} as Partial<Record<string, any>>;
for (const cloudData of cloudDatas) {
if (cloudData[1] != null) {
res[cloudData[0]] = cloudData[1].value;
}
}
return res;
},
};
export const prefer = createProfileManager(storageProvider);

View file

@ -79,6 +79,7 @@ export type PreferencesProfile = {
export type StorageProvider = {
save: (ctx: { profile: PreferencesProfile; }) => void;
cloudGets: <K extends keyof PREF>(ctx: { needs: { key: K; cond: Cond; }[] }) => Promise<Partial<Record<K, ValueOf<K>>>>;
cloudGet: <K extends keyof PREF>(ctx: { key: K; cond: Cond; }) => Promise<{ value: ValueOf<K>; } | null>;
cloudSet: <K extends keyof PREF>(ctx: { key: K; cond: Cond; value: ValueOf<K>; }) => Promise<void>;
};
@ -193,31 +194,34 @@ export class ProfileManager {
return states;
}
private fetchCloudValues() {
// TODO: 値の取得を1つのリクエストで済ませたい(バックエンド側でAPIの新設が必要)
const promises: Promise<void>[] = [];
private async fetchCloudValues() {
const needs = [] as { key: keyof PREF; cond: Cond; }[];
for (const key in PREF_DEF) {
const record = this.getMatchedRecordOf(key);
if (record[2].sync) {
const getting = this.storageProvider.cloudGet({ key, cond: record[0] });
promises.push(getting.then((res) => {
if (res == null) return;
const value = res.value;
if (value !== this.s[key]) {
this.rewriteRawState(key, value);
record[1] = value;
console.log('cloud fetched', key, value);
}
}));
needs.push({
key,
cond: record[0],
});
}
}
Promise.all(promises).then(() => {
console.log('cloud fetched all');
this.save();
console.log(this.s.showFixedPostForm, this.r.showFixedPostForm.value);
});
const cloudValues = await this.storageProvider.cloudGets({ needs });
for (const key in PREF_DEF) {
const record = this.getMatchedRecordOf(key);
if (record[2].sync && Object.hasOwn(cloudValues, key) && cloudValues[key] !== undefined) {
const cloudValue = cloudValues[key];
if (cloudValue !== this.s[key]) {
this.rewriteRawState(key, cloudValue);
record[1] = cloudValue;
console.log('cloud fetched', key, cloudValue);
}
}
}
this.save();
console.log('cloud fetch completed');
}
public static newProfile(): PreferencesProfile {