about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions/store.js
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-03-19 13:33:46 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-03-19 13:57:36 +0100
commit3b7b607300d662aa1f25d459ca12aec89ab550e8 (patch)
tree20788cbb86d4ae8d38ce539325205e5f0a1ee344 /app/javascript/flavours/glitch/actions/store.js
parentdb6551ec09cd8f38a9448ba6f4caae56f7a9bb3d (diff)
Migrate glitch-soc local notification settings to upstream system
Diffstat (limited to 'app/javascript/flavours/glitch/actions/store.js')
-rw-r--r--app/javascript/flavours/glitch/actions/store.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/javascript/flavours/glitch/actions/store.js b/app/javascript/flavours/glitch/actions/store.js
index 34dcafc51..9dbc0b214 100644
--- a/app/javascript/flavours/glitch/actions/store.js
+++ b/app/javascript/flavours/glitch/actions/store.js
@@ -1,6 +1,7 @@
 import { Iterable, fromJS } from 'immutable';
 import { hydrateCompose } from './compose';
 import { importFetchedAccounts } from './importer';
+import { saveSettings } from './settings';
 
 export const STORE_HYDRATE = 'STORE_HYDRATE';
 export const STORE_HYDRATE_LAZY = 'STORE_HYDRATE_LAZY';
@@ -9,9 +10,22 @@ const convertState = rawState =>
   fromJS(rawState, (k, v) =>
     Iterable.isIndexed(v) ? v.toList() : v.toMap());
 
+const applyMigrations = (state) => {
+  return state.withMutations(state => {
+    // Migrate glitch-soc local-only “Show unread marker” setting to Mastodon's setting
+    if (state.getIn(['local_settings', 'notifications', 'show_unread']) !== undefined) {
+      // Only change if the Mastodon setting does not deviate from default
+      if (state.getIn(['settings', 'notifications', 'showUnread']) !== false) {
+        state.setIn(['settings', 'notifications', 'showUnread'], state.getIn(['local_settings', 'notifications', 'show_unread']));
+      }
+      state.removeIn(['local_settings', 'notifications', 'show_unread'])
+    }
+  });
+};
+
 export function hydrateStore(rawState) {
   return dispatch => {
-    const state = convertState(rawState);
+    const state = applyMigrations(convertState(rawState));
 
     dispatch({
       type: STORE_HYDRATE,
@@ -20,5 +34,6 @@ export function hydrateStore(rawState) {
 
     dispatch(hydrateCompose());
     dispatch(importFetchedAccounts(Object.values(rawState.accounts)));
+    dispatch(saveSettings());
   };
 };