Commit 68105a39 authored by Haelwenn's avatar Haelwenn

Merge branch 'features/notification-settings' into 'rebase/glitch-soc'

Add support for notification_settings

See merge request !30
parents 4788384b 4b041c15
Pipeline #29093 passed with stage
in 5 minutes and 17 seconds
......@@ -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 => {
......
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,11 @@ 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()) }
).catch(error => dispatch(showAlertForError(error)));
api(getState).put('/api/web/settings', { data })
.then(() => dispatch({ type: SETTING_SAVE }))
.catch(error => dispatch(showAlertForError(error)));
......
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;
}();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment