From 20b132f38888ae0e6bc66021db8b3ffdbefae703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Sat, 7 Mar 2026 10:30:33 +0100 Subject: [PATCH] nicolium: make settings synchronization in notes opt-in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/nicolium/src/actions/me.ts | 9 ++- packages/nicolium/src/actions/settings.ts | 58 +++++++++++-------- .../src/features/preferences/index.tsx | 50 ++++++++-------- packages/nicolium/src/locales/en.json | 2 + 4 files changed, 68 insertions(+), 51 deletions(-) diff --git a/packages/nicolium/src/actions/me.ts b/packages/nicolium/src/actions/me.ts index 221b10b44..d63210fad 100644 --- a/packages/nicolium/src/actions/me.ts +++ b/packages/nicolium/src/actions/me.ts @@ -99,9 +99,11 @@ const fetchMeSuccess = const settings = account.settings_store?.[FE_NAME] || account.settings_store?.[LEGACY_FE_NAME]; - if (client.features.frontendConfigurations) { + if (settings) { useSettingsStore.getState().actions.loadUserSettings(settings); - } else if (client.features.notes) { + } + + if (!client.features.frontendConfigurations && client.features.notes) { const note = await getClient(getState) .accounts.getRelationships([account.id]) .then((relationships) => relationships[0]?.note); @@ -112,6 +114,9 @@ const fetchMeSuccess = if (match) { try { const frontendConfig = JSON.parse(decodeURIComponent(match[1])); + if (typeof frontendConfig === 'object' && frontendConfig !== null) { + frontendConfig.storeSettingsInNotes = true; + } useSettingsStore.getState().actions.loadUserSettings(frontendConfig); return frontendConfig; } catch (error) { diff --git a/packages/nicolium/src/actions/settings.ts b/packages/nicolium/src/actions/settings.ts index cd99b66c2..fce73e8e2 100644 --- a/packages/nicolium/src/actions/settings.ts +++ b/packages/nicolium/src/actions/settings.ts @@ -10,6 +10,7 @@ import { useSettingsStore } from '@/stores/settings'; import toast from '@/toast'; import { isLoggedIn } from '@/utils/auth'; +import type { Settings } from '@/schemas/frontend-settings'; import type { AppDispatch, RootState } from '@/store'; const LEGACY_FE_NAME = NODE_ENV === 'production' ? 'pl_fe' : 'pl_fe_dev'; @@ -30,33 +31,35 @@ const saveSuccessMessage = defineMessage({ const changeSetting = (path: string[], value: any, opts?: SettingOpts) => { useSettingsStore.getState().actions.changeSetting(path, value); - if (opts?.save !== false) return saveSettings(opts); + if (opts?.save !== false) return saveSettings(opts, path[0] === 'storeSettingsInNotes'); return () => {}; }; -const saveSettings = (opts?: SettingOpts) => (dispatch: AppDispatch, getState: () => RootState) => { - if (!isLoggedIn(getState)) return; +const saveSettings = + (opts?: SettingOpts, isNotesChange?: boolean) => + (dispatch: AppDispatch, getState: () => RootState) => { + if (!isLoggedIn(getState)) return; - const { - userSettings, - actions: { userSettingsSaving }, - } = useSettingsStore.getState(); - if (userSettings.saved) return; + const { + userSettings, + actions: { userSettingsSaving }, + } = useSettingsStore.getState(); + if (userSettings.saved) return; - const { saved, ...data } = userSettings; + const { saved, ...data } = userSettings; - dispatch(updateSettingsStore(data)) - .then(() => { - userSettingsSaving(); + dispatch(updateSettingsStore(data, isNotesChange)) + .then(() => { + userSettingsSaving(); - if (opts?.showAlert) { - toast.success(saveSuccessMessage); - } - }) - .catch((error) => { - toast.showAlertForError(error); - }); -}; + if (opts?.showAlert) { + toast.success(saveSuccessMessage); + } + }) + .catch((error) => { + toast.showAlertForError(error); + }); + }; /** Update settings store for Mastodon, etc. */ const updateAuthAccount = async (url: string, settings: any) => { @@ -73,7 +76,8 @@ const updateAuthAccount = async (url: string, settings: any) => { }; const updateSettingsStore = - (settings: any) => async (dispatch: AppDispatch, getState: () => RootState) => { + (settings: Partial, isNotesChange?: boolean) => + async (dispatch: AppDispatch, getState: () => RootState) => { const state = getState(); const client = getClient(state); @@ -86,17 +90,21 @@ const updateSettingsStore = }), ); } else { - if (client.features.notes) { + if (client.features.notes && (settings.storeSettingsInNotes || isNotesChange)) { // Inspired by Phanpy and designed for compatibility with other software doing this // https://github.com/cheeaun/phanpy/commit/a8b5c8cd64d456d30aab09dc56da7e4e20100e67 const note = (await client.accounts.getRelationships([state.me as string]))[0]?.note; const settingsNote = `${encodeURIComponent(JSON.stringify(settings))}`; let newNote; - if (/(.*)<\/nicolium-config>/.test(note || '')) { - newNote = note!.replace(/(.*)<\/nicolium-config>/, settingsNote); + if (settings.storeSettingsInNotes) { + if (/(.*)<\/nicolium-config>/.test(note || '')) { + newNote = note!.replace(/(.*)<\/nicolium-config>/, settingsNote); + } else { + newNote = `${note || ''}\n\n${settingsNote}`; + } } else { - newNote = `${note || ''}\n\n${settingsNote}`; + newNote = note ? note.replace(/(.*)<\/nicolium-config>/, '') : ''; } client.accounts.updateAccountNote(state.me as string, newNote); } diff --git a/packages/nicolium/src/features/preferences/index.tsx b/packages/nicolium/src/features/preferences/index.tsx index 0d504ff25..299a3a104 100644 --- a/packages/nicolium/src/features/preferences/index.tsx +++ b/packages/nicolium/src/features/preferences/index.tsx @@ -282,6 +282,32 @@ const Preferences = () => { return (
+ {!features.frontendConfigurations && features.notes && ( + + + } + hint={ + + } + > + + + + )} + { onChange={onToggleChange} /> - - - - {/* - } - hint={ - - } - > - - */}