Merge branch 'features/notification-settings' into 'rebase/glitch-soc'
Add support for notification_settings See merge request pleroma/mastofe!30
This commit is contained in:
commit
68105a39bf
3 changed files with 21 additions and 1 deletions
|
@ -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 => {
|
const excludeTypesFromFilter = filter => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import api from 'flavours/glitch/util/api';
|
import api from 'flavours/glitch/util/api';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { showAlertForError } from './alerts';
|
import { showAlertForError } from './alerts';
|
||||||
|
import { excludeTypesFromSettings } from './notifications';
|
||||||
|
|
||||||
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
||||||
export const SETTING_SAVE = 'SETTING_SAVE';
|
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();
|
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 })
|
api(getState).put('/api/web/settings', { data })
|
||||||
.then(() => dispatch({ type: SETTING_SAVE }))
|
.then(() => dispatch({ type: SETTING_SAVE }))
|
||||||
.catch(error => dispatch(showAlertForError(error)));
|
.catch(error => dispatch(showAlertForError(error)));
|
||||||
|
|
|
@ -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 element = document.getElementById('initial-state');
|
||||||
const initialState = element && function () {
|
const initialState = element && function () {
|
||||||
const result = JSON.parse(element.textContent);
|
const result = JSON.parse(element.textContent);
|
||||||
|
@ -6,6 +19,7 @@ const initialState = element && function () {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result.local_settings = {};
|
result.local_settings = {};
|
||||||
}
|
}
|
||||||
|
maybeSetNotificationsSettings(result);
|
||||||
return result;
|
return result;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue