summaryrefslogtreecommitdiff
path: root/packages/frontend/src/preferences/def.ts
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-05-31 14:15:40 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-05-31 14:15:40 +0900
commit743995e4695af1ade073172f87fc91f1c9b37ba8 (patch)
tree121e0208eda42498b6b5f3565b11a47bcdcfb1db /packages/frontend/src/preferences/def.ts
parentenhance(frontend): 設定の同期をオンにするときに競合したと... (diff)
downloadmisskey-743995e4695af1ade073172f87fc91f1c9b37ba8.tar.gz
misskey-743995e4695af1ade073172f87fc91f1c9b37ba8.tar.bz2
misskey-743995e4695af1ade073172f87fc91f1c9b37ba8.zip
enhance(frontend): make pref sync more smart
Diffstat (limited to 'packages/frontend/src/preferences/def.ts')
-rw-r--r--packages/frontend/src/preferences/def.ts35
1 files changed, 29 insertions, 6 deletions
diff --git a/packages/frontend/src/preferences/def.ts b/packages/frontend/src/preferences/def.ts
index b8a5a84279..86d5c8af98 100644
--- a/packages/frontend/src/preferences/def.ts
+++ b/packages/frontend/src/preferences/def.ts
@@ -13,6 +13,7 @@ import type { DeviceKind } from '@/utility/device-kind.js';
import type { DeckProfile } from '@/deck.js';
import type { PreferencesDefinition } from './manager.js';
import { DEFAULT_DEVICE_KIND } from '@/utility/device-kind.js';
+import { deepEqual } from '@/utility/deep-equal.js';
/** サウンド設定 */
export type SoundStore = {
@@ -87,9 +88,20 @@ export const PREF_DEF = {
emojis: string[];
}[],
mergeStrategy: (a, b) => {
- const sameIdExists = a.some(x => b.some(y => x.id === y.id));
- if (sameIdExists) throw new Error();
- return a.concat(b);
+ const mergedItems = [] as (typeof a)[];
+ for (const x of a.concat(b)) {
+ const sameIdItem = mergedItems.find(y => y.id === x.id);
+ if (sameIdItem != null) {
+ if (deepEqual(x, sameIdItem)) { // 完全な重複は無視
+ continue;
+ } else { // IDは同じなのに内容が違う場合はマージ不可とする
+ throw new Error();
+ }
+ } else {
+ mergedItems.push(x);
+ }
+ }
+ return mergedItems;
},
},
emojiPaletteForReaction: {
@@ -107,9 +119,20 @@ export const PREF_DEF = {
themes: {
default: [] as Theme[],
mergeStrategy: (a, b) => {
- const sameIdExists = a.some(x => b.some(y => x.id === y.id));
- if (sameIdExists) throw new Error();
- return a.concat(b);
+ const mergedItems = [] as (typeof a)[];
+ for (const x of a.concat(b)) {
+ const sameIdItem = mergedItems.find(y => y.id === x.id);
+ if (sameIdItem != null) {
+ if (deepEqual(x, sameIdItem)) { // 完全な重複は無視
+ continue;
+ } else { // IDは同じなのに内容が違う場合はマージ不可とする
+ throw new Error();
+ }
+ } else {
+ mergedItems.push(x);
+ }
+ }
+ return mergedItems;
},
},
lightTheme: {