fix: sync the setting that deletes junk mail for good between devices

This commit is contained in:
Linus Rath
2026-11-02 23:14:22 +01:00
parent 8905d31b38
commit c7e88c249e
2 changed files with 36 additions and 0 deletions
@@ -0,0 +1,31 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { useSettingsStore } from '../settings-store';
// "Permanently delete junk" is a choice on the Message list page; it has to
// reach the server copy like the rest, or another device (or a restore)
// quietly goes back to moving junk to the trash.
describe('settings-store permanentlyDeleteJunk sync', () => {
beforeEach(() => {
useSettingsStore.getState().resetToDefaults();
});
it('is in the snapshot pushed to the server and in a file export', () => {
useSettingsStore.getState().updateSetting('permanentlyDeleteJunk', true);
expect(JSON.parse(useSettingsStore.getState().exportSettings({ forSync: true })).permanentlyDeleteJunk).toBe(true);
expect(JSON.parse(useSettingsStore.getState().exportSettings()).permanentlyDeleteJunk).toBe(true);
});
it('comes back from a synced copy', () => {
useSettingsStore.getState().updateSetting('permanentlyDeleteJunk', true);
const blob = useSettingsStore.getState().exportSettings({ forSync: true });
useSettingsStore.getState().resetToDefaults();
expect(useSettingsStore.getState().permanentlyDeleteJunk).toBe(false);
expect(useSettingsStore.getState().importSettings(blob)).toBe(true);
expect(useSettingsStore.getState().permanentlyDeleteJunk).toBe(true);
});
it('ignores a value that is not a boolean', () => {
expect(useSettingsStore.getState().importSettings(JSON.stringify({ permanentlyDeleteJunk: 'yes' }))).toBe(true);
expect(useSettingsStore.getState().permanentlyDeleteJunk).toBe(false);
});
});
+5
View File
@@ -1334,6 +1334,7 @@ export const useSettingsStore = create<SettingsState>()(
deleteAction: state.deleteAction,
returnToListAfterAction: state.returnToListAfterAction,
confirmBulkDelete: state.confirmBulkDelete,
permanentlyDeleteJunk: state.permanentlyDeleteJunk,
clearSearchOnFolderChange: state.clearSearchOnFolderChange,
searchDefaultScope: state.searchDefaultScope,
showPreview: state.showPreview,
@@ -1635,6 +1636,10 @@ export const useSettingsStore = create<SettingsState>()(
if (key === 'searchDefaultScope' && !isSearchDefaultScope(settings[key])) {
return;
}
// Anything but a real true must not turn on deleting junk for good.
if (key === 'permanentlyDeleteJunk' && typeof settings[key] !== 'boolean') {
return;
}
if (DEVICE_LOCAL_SETTING_KEYS.has(key)) {
return;
}