2020-03-27 13:59:38 -07:00
|
|
|
import { debounce } from 'lodash';
|
|
|
|
import { showAlertForError } from './alerts';
|
2020-05-28 15:52:07 -07:00
|
|
|
import { patchMe } from 'soapbox/actions/me';
|
2021-08-11 16:23:42 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2021-03-25 10:25:45 -07:00
|
|
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
2020-09-27 17:43:42 -07:00
|
|
|
import uuid from '../uuid';
|
2021-07-06 11:06:21 -07:00
|
|
|
import { createSelector } from 'reselect';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
export const SETTING_CHANGE = 'SETTING_CHANGE';
|
|
|
|
export const SETTING_SAVE = 'SETTING_SAVE';
|
|
|
|
|
2020-04-18 11:58:51 -07:00
|
|
|
export const FE_NAME = 'soapbox_fe';
|
|
|
|
|
2020-10-01 16:57:11 -07:00
|
|
|
export const defaultSettings = ImmutableMap({
|
2020-04-28 10:59:15 -07:00
|
|
|
onboarded: false,
|
|
|
|
|
|
|
|
skinTone: 1,
|
|
|
|
reduceMotion: false,
|
2021-07-28 07:03:14 -07:00
|
|
|
underlineLinks: false,
|
2020-05-28 13:43:17 -07:00
|
|
|
autoPlayGif: true,
|
2020-05-28 18:36:39 -07:00
|
|
|
displayMedia: 'default',
|
2020-04-28 10:59:15 -07:00
|
|
|
expandSpoilers: false,
|
|
|
|
unfollowModal: false,
|
|
|
|
boostModal: false,
|
|
|
|
deleteModal: true,
|
2021-06-21 11:33:05 -07:00
|
|
|
missingDescriptionModal: false,
|
2020-04-28 10:59:15 -07:00
|
|
|
defaultPrivacy: 'public',
|
2020-12-24 12:20:07 -08:00
|
|
|
defaultContentType: 'text/plain',
|
2020-06-02 10:16:26 -07:00
|
|
|
themeMode: 'light',
|
2020-06-04 15:29:00 -07:00
|
|
|
locale: navigator.language.split(/[-_]/)[0] || 'en',
|
2021-04-26 10:11:47 -07:00
|
|
|
showExplanationBox: true,
|
2020-07-26 15:30:54 -07:00
|
|
|
explanationBox: true,
|
2020-08-07 13:17:13 -07:00
|
|
|
otpEnabled: false,
|
2020-04-28 10:59:15 -07:00
|
|
|
|
|
|
|
systemFont: false,
|
|
|
|
dyslexicFont: false,
|
|
|
|
demetricator: false,
|
|
|
|
|
2020-08-25 12:58:35 -07:00
|
|
|
chats: ImmutableMap({
|
|
|
|
panes: ImmutableList(),
|
|
|
|
mainWindow: 'minimized',
|
2020-09-04 19:43:14 -07:00
|
|
|
sound: true,
|
2020-08-25 12:58:35 -07:00
|
|
|
}),
|
|
|
|
|
2020-04-28 10:59:15 -07:00
|
|
|
home: ImmutableMap({
|
|
|
|
shows: ImmutableMap({
|
|
|
|
reblog: true,
|
|
|
|
reply: true,
|
2020-08-07 18:47:04 -07:00
|
|
|
direct: false,
|
2020-04-28 10:59:15 -07:00
|
|
|
}),
|
|
|
|
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
notifications: ImmutableMap({
|
|
|
|
alerts: ImmutableMap({
|
|
|
|
follow: true,
|
2021-03-29 11:35:30 -07:00
|
|
|
follow_request: false,
|
2020-04-28 10:59:15 -07:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
|
|
|
mention: true,
|
|
|
|
poll: true,
|
2021-06-30 04:41:06 -07:00
|
|
|
move: true,
|
2021-01-19 16:50:08 -08:00
|
|
|
'pleroma:emoji_reaction': true,
|
2020-04-28 10:59:15 -07:00
|
|
|
}),
|
|
|
|
|
|
|
|
quickFilter: ImmutableMap({
|
|
|
|
active: 'all',
|
|
|
|
show: true,
|
|
|
|
advanced: false,
|
|
|
|
}),
|
|
|
|
|
|
|
|
shows: ImmutableMap({
|
|
|
|
follow: true,
|
2021-03-29 11:35:30 -07:00
|
|
|
follow_request: false,
|
2020-04-28 10:59:15 -07:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
|
|
|
mention: true,
|
|
|
|
poll: true,
|
2021-06-30 04:41:06 -07:00
|
|
|
move: true,
|
2021-01-19 16:50:08 -08:00
|
|
|
'pleroma:emoji_reaction': true,
|
2020-04-28 10:59:15 -07:00
|
|
|
}),
|
|
|
|
|
|
|
|
sounds: ImmutableMap({
|
2020-05-18 17:43:58 -07:00
|
|
|
follow: false,
|
2021-03-29 11:35:30 -07:00
|
|
|
follow_request: false,
|
2020-05-18 17:43:58 -07:00
|
|
|
favourite: false,
|
|
|
|
reblog: false,
|
|
|
|
mention: false,
|
|
|
|
poll: false,
|
2021-06-30 04:41:06 -07:00
|
|
|
move: false,
|
2021-01-19 16:50:08 -08:00
|
|
|
'pleroma:emoji_reaction': false,
|
2020-04-28 10:59:15 -07:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
community: ImmutableMap({
|
2020-08-07 17:28:30 -07:00
|
|
|
shows: ImmutableMap({
|
2020-08-14 10:42:03 -07:00
|
|
|
reblog: false,
|
2020-08-07 17:28:30 -07:00
|
|
|
reply: true,
|
|
|
|
}),
|
2020-04-28 10:59:15 -07:00
|
|
|
other: ImmutableMap({
|
|
|
|
onlyMedia: false,
|
|
|
|
}),
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
public: ImmutableMap({
|
2020-08-07 17:28:30 -07:00
|
|
|
shows: ImmutableMap({
|
|
|
|
reblog: true,
|
|
|
|
reply: true,
|
|
|
|
}),
|
2020-04-28 10:59:15 -07:00
|
|
|
other: ImmutableMap({
|
|
|
|
onlyMedia: false,
|
|
|
|
}),
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
direct: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2021-08-11 13:31:46 -07:00
|
|
|
account_timeline: ImmutableMap({
|
|
|
|
shows: ImmutableMap({
|
|
|
|
reblog: true,
|
2021-08-11 14:00:49 -07:00
|
|
|
pinned: true,
|
2021-08-11 13:31:46 -07:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2020-04-28 10:59:15 -07:00
|
|
|
trends: ImmutableMap({
|
|
|
|
show: true,
|
|
|
|
}),
|
2020-09-27 17:43:42 -07:00
|
|
|
|
|
|
|
columns: ImmutableList([
|
|
|
|
ImmutableMap({ id: 'COMPOSE', uuid: uuid(), params: {} }),
|
|
|
|
ImmutableMap({ id: 'HOME', uuid: uuid(), params: {} }),
|
|
|
|
ImmutableMap({ id: 'NOTIFICATIONS', uuid: uuid(), params: {} }),
|
|
|
|
]),
|
2021-08-11 16:23:42 -07:00
|
|
|
|
|
|
|
remote_timeline: ImmutableMap({
|
|
|
|
pinnedHosts: ImmutableOrderedSet(),
|
|
|
|
}),
|
2020-04-28 10:59:15 -07:00
|
|
|
});
|
|
|
|
|
2021-07-06 11:06:21 -07:00
|
|
|
export const getSettings = createSelector([
|
|
|
|
state => state.getIn(['soapbox', 'defaultSettings']),
|
|
|
|
state => state.get('settings'),
|
|
|
|
], (soapboxSettings, settings) => {
|
2020-04-28 10:59:15 -07:00
|
|
|
return defaultSettings
|
|
|
|
.mergeDeep(soapboxSettings)
|
2021-07-06 11:06:21 -07:00
|
|
|
.mergeDeep(settings);
|
|
|
|
});
|
2020-04-28 10:59:15 -07:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
export function changeSetting(path, value) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: SETTING_CHANGE,
|
|
|
|
path,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(saveSettings());
|
|
|
|
};
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
const debouncedSave = debounce((dispatch, getState) => {
|
2021-03-24 09:52:12 -07:00
|
|
|
if (!isLoggedIn(getState)) return;
|
|
|
|
|
2020-04-21 13:53:32 -07:00
|
|
|
const state = getState();
|
2020-04-28 11:49:39 -07:00
|
|
|
if (getSettings(state).getIn(['saved'])) return;
|
2020-04-18 11:58:51 -07:00
|
|
|
|
2020-04-21 13:53:32 -07:00
|
|
|
const data = state.get('settings').delete('saved').toJS();
|
2020-04-18 11:58:51 -07:00
|
|
|
|
2020-04-21 13:53:32 -07:00
|
|
|
dispatch(patchMe({
|
2020-04-18 11:58:51 -07:00
|
|
|
pleroma_settings_store: {
|
|
|
|
[FE_NAME]: data,
|
|
|
|
},
|
2020-04-21 13:53:32 -07:00
|
|
|
})).then(response => {
|
2020-04-18 11:58:51 -07:00
|
|
|
dispatch({ type: SETTING_SAVE });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(showAlertForError(error));
|
|
|
|
});
|
2020-03-27 13:59:38 -07:00
|
|
|
}, 5000, { trailing: true });
|
|
|
|
|
|
|
|
export function saveSettings() {
|
|
|
|
return (dispatch, getState) => debouncedSave(dispatch, getState);
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|