From cfefd0aecd023c17e7550ad79049fdc3e95213de Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 30 Jun 2020 01:25:08 +0200 Subject: [PATCH 1/2] Sync notification_settings --- app/javascript/flavours/glitch/actions/notifications.js | 2 +- app/javascript/flavours/glitch/actions/settings.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index b3de7b5bf..cf91a58c8 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -117,7 +117,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) { }; }; -const excludeTypesFromSettings = state => state.getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS(); +export const excludeTypesFromSettings = state => state.getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS(); const excludeTypesFromFilter = filter => { diff --git a/app/javascript/flavours/glitch/actions/settings.js b/app/javascript/flavours/glitch/actions/settings.js index fb0bcc09c..5b44f7b9a 100644 --- a/app/javascript/flavours/glitch/actions/settings.js +++ b/app/javascript/flavours/glitch/actions/settings.js @@ -1,6 +1,7 @@ import api from 'flavours/glitch/util/api'; import { debounce } from 'lodash'; import { showAlertForError } from './alerts'; +import { excludeTypesFromSettings } from './notifications'; export const SETTING_CHANGE = 'SETTING_CHANGE'; export const SETTING_SAVE = 'SETTING_SAVE'; @@ -24,6 +25,8 @@ const debouncedSave = debounce((dispatch, getState) => { const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS(); + api(getState).put('/api/pleroma/notification_settings', { exclude_types: excludeTypesFromSettings(getState()) }); + api(getState).put('/api/web/settings', { data }) .then(() => dispatch({ type: SETTING_SAVE })) .catch(error => dispatch(showAlertForError(error))); From 4b041c15512711c8481bb30565eaba38cf3f4e3a Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 30 Jun 2020 02:30:03 +0200 Subject: [PATCH 2/2] initial_state: sync notifications.shows with pleroma notification_settings lodash suggestion from Alex Gleason --- app/javascript/flavours/glitch/actions/settings.js | 5 ++++- .../flavours/glitch/util/initial_state.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/actions/settings.js b/app/javascript/flavours/glitch/actions/settings.js index 5b44f7b9a..02b52ce02 100644 --- a/app/javascript/flavours/glitch/actions/settings.js +++ b/app/javascript/flavours/glitch/actions/settings.js @@ -25,7 +25,10 @@ const debouncedSave = debounce((dispatch, getState) => { const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS(); - api(getState).put('/api/pleroma/notification_settings', { exclude_types: excludeTypesFromSettings(getState()) }); + api(getState).put( + '/api/pleroma/notification_settings', + { exclude_types: excludeTypesFromSettings(getState()) } + ).catch(error => dispatch(showAlertForError(error))); api(getState).put('/api/web/settings', { data }) .then(() => dispatch({ type: SETTING_SAVE })) diff --git a/app/javascript/flavours/glitch/util/initial_state.js b/app/javascript/flavours/glitch/util/initial_state.js index 642c49918..267bf0b48 100644 --- a/app/javascript/flavours/glitch/util/initial_state.js +++ b/app/javascript/flavours/glitch/util/initial_state.js @@ -1,3 +1,16 @@ +import { get, set } from 'lodash'; + +const maybeSetNotificationsSettings = result => { + const me = get(result, ['meta', 'me']); + if(!me) return; + + const showTypes = get(result, ['settings', 'notifications', 'shows'], {}); + const excludeTypes = get(result, ['accounts', me, 'pleroma', 'notification_settings', 'exclude_types'], []); + + excludeTypes.forEach(x => showTypes[x] = false); + set(result, ['settings', 'notifications', 'shows'], showTypes); +} + const element = document.getElementById('initial-state'); const initialState = element && function () { const result = JSON.parse(element.textContent); @@ -6,6 +19,7 @@ const initialState = element && function () { } catch (e) { result.local_settings = {}; } + maybeSetNotificationsSettings(result); return result; }();