2023-05-28 14:38:10 +00:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
|
|
|
|
2023-11-15 11:01:51 +00:00
|
|
|
import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE, COLUMN_PARAMS_CHANGE } from '../actions/columns';
|
|
|
|
import { EMOJI_USE } from '../actions/emojis';
|
|
|
|
import { LANGUAGE_USE } from '../actions/languages';
|
2017-12-09 02:13:08 +00:00
|
|
|
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists';
|
2023-11-15 11:01:51 +00:00
|
|
|
import { NOTIFICATIONS_FILTER_SET } from '../actions/notifications';
|
|
|
|
import { SETTING_CHANGE, SETTING_SAVE } from '../actions/settings';
|
|
|
|
import { STORE_HYDRATE } from '../actions/store';
|
2023-05-09 01:11:56 +00:00
|
|
|
import { uuid } from '../uuid';
|
2017-01-09 13:00:55 +00:00
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
const initialState = ImmutableMap({
|
2017-10-08 19:47:15 +00:00
|
|
|
saved: true,
|
|
|
|
|
2017-04-16 18:32:00 +00:00
|
|
|
onboarded: false,
|
2017-06-25 00:07:25 +00:00
|
|
|
layout: 'auto',
|
2017-04-16 18:32:00 +00:00
|
|
|
|
2017-10-07 17:02:30 +00:00
|
|
|
skinTone: 1,
|
|
|
|
|
2019-08-06 15:57:52 +00:00
|
|
|
trends: ImmutableMap({
|
|
|
|
show: true,
|
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
home: ImmutableMap({
|
|
|
|
shows: ImmutableMap({
|
2017-01-10 16:25:10 +00:00
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
reply: true,
|
2017-12-07 01:50:27 +00:00
|
|
|
direct: true,
|
2017-05-03 00:04:16 +00:00
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
regex: ImmutableMap({
|
2017-05-20 15:31:47 +00:00
|
|
|
body: '',
|
|
|
|
}),
|
2017-01-10 16:25:10 +00:00
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
notifications: ImmutableMap({
|
|
|
|
alerts: ImmutableMap({
|
2020-10-12 22:37:21 +00:00
|
|
|
follow: false,
|
2019-12-01 16:25:29 +00:00
|
|
|
follow_request: false,
|
2020-10-12 22:37:21 +00:00
|
|
|
favourite: false,
|
|
|
|
reblog: false,
|
|
|
|
mention: false,
|
|
|
|
poll: false,
|
2020-10-15 14:24:47 +00:00
|
|
|
status: false,
|
2022-02-11 21:20:19 +00:00
|
|
|
update: false,
|
2022-02-23 15:45:22 +00:00
|
|
|
'admin.sign_up': false,
|
2022-06-27 07:30:15 +00:00
|
|
|
'admin.report': false,
|
2017-01-09 13:00:55 +00:00
|
|
|
}),
|
|
|
|
|
2018-12-18 16:22:01 +00:00
|
|
|
quickFilter: ImmutableMap({
|
|
|
|
active: 'all',
|
|
|
|
show: true,
|
|
|
|
advanced: false,
|
|
|
|
}),
|
|
|
|
|
2020-12-15 17:43:54 +00:00
|
|
|
dismissPermissionBanner: false,
|
2021-03-19 11:47:31 +00:00
|
|
|
showUnread: true,
|
2020-12-15 17:43:54 +00:00
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
shows: ImmutableMap({
|
2017-01-09 13:00:55 +00:00
|
|
|
follow: true,
|
2019-12-01 16:25:29 +00:00
|
|
|
follow_request: false,
|
2017-01-09 13:00:55 +00:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
mention: true,
|
2019-03-11 10:32:21 +00:00
|
|
|
poll: true,
|
2020-10-15 14:24:47 +00:00
|
|
|
status: true,
|
2022-02-11 21:20:19 +00:00
|
|
|
update: true,
|
2022-02-23 15:45:22 +00:00
|
|
|
'admin.sign_up': true,
|
2022-06-27 07:30:15 +00:00
|
|
|
'admin.report': true,
|
2017-01-17 19:09:03 +00:00
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
sounds: ImmutableMap({
|
2017-01-17 19:09:03 +00:00
|
|
|
follow: true,
|
2019-12-01 16:25:29 +00:00
|
|
|
follow_request: false,
|
2017-01-17 19:09:03 +00:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 15:31:47 +00:00
|
|
|
mention: true,
|
2019-03-11 10:32:21 +00:00
|
|
|
poll: true,
|
2020-10-15 14:24:47 +00:00
|
|
|
status: true,
|
2022-02-11 21:20:19 +00:00
|
|
|
update: true,
|
2022-02-23 15:45:22 +00:00
|
|
|
'admin.sign_up': true,
|
2022-06-27 07:30:15 +00:00
|
|
|
'admin.report': true,
|
2017-05-20 15:31:47 +00:00
|
|
|
}),
|
2017-06-06 14:56:10 +00:00
|
|
|
}),
|
|
|
|
|
2023-07-01 22:05:10 +00:00
|
|
|
firehose: ImmutableMap({
|
|
|
|
onlyMedia: false,
|
2023-07-02 18:24:27 +00:00
|
|
|
allowLocalOnly: true,
|
2023-07-03 13:41:50 +00:00
|
|
|
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
2023-07-01 22:05:10 +00:00
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
community: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
2017-06-06 14:56:10 +00:00
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
public: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
2017-06-06 14:56:10 +00:00
|
|
|
body: '',
|
|
|
|
}),
|
2017-05-20 15:31:47 +00:00
|
|
|
}),
|
2017-10-16 04:02:39 +00:00
|
|
|
|
|
|
|
direct: ImmutableMap({
|
2019-06-09 10:07:23 +00:00
|
|
|
conversations: true,
|
2017-10-16 04:02:39 +00:00
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
2017-01-09 13:00:55 +00:00
|
|
|
});
|
|
|
|
|
2017-07-10 23:00:14 +00:00
|
|
|
const defaultColumns = fromJS([
|
2017-06-14 19:59:52 +00:00
|
|
|
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'HOME', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
|
|
|
]);
|
|
|
|
|
2017-06-14 21:07:06 +00:00
|
|
|
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
|
2017-06-14 19:59:52 +00:00
|
|
|
|
2017-06-03 23:39:38 +00:00
|
|
|
const moveColumn = (state, uuid, direction) => {
|
|
|
|
const columns = state.get('columns');
|
|
|
|
const index = columns.findIndex(item => item.get('uuid') === uuid);
|
|
|
|
const newIndex = index + direction;
|
|
|
|
|
|
|
|
let newColumns;
|
|
|
|
|
|
|
|
newColumns = columns.splice(index, 1);
|
|
|
|
newColumns = newColumns.splice(newIndex, 0, columns.get(index));
|
|
|
|
|
2017-10-08 19:47:15 +00:00
|
|
|
return state
|
|
|
|
.set('columns', newColumns)
|
|
|
|
.set('saved', false);
|
2017-06-03 23:39:38 +00:00
|
|
|
};
|
|
|
|
|
2018-12-18 17:52:37 +00:00
|
|
|
const changeColumnParams = (state, uuid, path, value) => {
|
2018-05-27 19:26:33 +00:00
|
|
|
const columns = state.get('columns');
|
|
|
|
const index = columns.findIndex(item => item.get('uuid') === uuid);
|
|
|
|
|
2018-12-18 17:52:37 +00:00
|
|
|
const newColumns = columns.update(index, column => column.updateIn(['params', ...path], () => value));
|
2018-05-27 19:26:33 +00:00
|
|
|
|
|
|
|
return state
|
|
|
|
.set('columns', newColumns)
|
|
|
|
.set('saved', false);
|
|
|
|
};
|
|
|
|
|
2017-10-08 19:47:15 +00:00
|
|
|
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false);
|
|
|
|
|
2022-05-16 09:18:35 +00:00
|
|
|
const updateFrequentLanguages = (state, language) => state.update('frequentlyUsedLanguages', ImmutableMap(), map => map.update(language, 0, count => count + 1)).set('saved', false);
|
|
|
|
|
2017-12-09 02:13:08 +00:00
|
|
|
const filterDeadListColumns = (state, listId) => state.update('columns', columns => columns.filterNot(column => column.get('id') === 'LIST' && column.get('params').get('id') === listId));
|
|
|
|
|
2017-01-09 13:00:55 +00:00
|
|
|
export default function settings(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE:
|
2017-06-14 21:07:06 +00:00
|
|
|
return hydrate(state, action.state.get('settings'));
|
2018-12-18 16:22:01 +00:00
|
|
|
case NOTIFICATIONS_FILTER_SET:
|
2017-01-09 13:00:55 +00:00
|
|
|
case SETTING_CHANGE:
|
2017-10-08 19:47:15 +00:00
|
|
|
return state
|
2018-01-09 15:48:14 +00:00
|
|
|
.setIn(action.path, action.value)
|
2017-10-08 19:47:15 +00:00
|
|
|
.set('saved', false);
|
2017-06-03 23:39:38 +00:00
|
|
|
case COLUMN_ADD:
|
2017-10-08 19:47:15 +00:00
|
|
|
return state
|
|
|
|
.update('columns', list => list.push(fromJS({ id: action.id, uuid: uuid(), params: action.params })))
|
|
|
|
.set('saved', false);
|
2017-06-03 23:39:38 +00:00
|
|
|
case COLUMN_REMOVE:
|
2017-10-08 19:47:15 +00:00
|
|
|
return state
|
|
|
|
.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid))
|
|
|
|
.set('saved', false);
|
2017-06-03 23:39:38 +00:00
|
|
|
case COLUMN_MOVE:
|
|
|
|
return moveColumn(state, action.uuid, action.direction);
|
2018-05-27 19:26:33 +00:00
|
|
|
case COLUMN_PARAMS_CHANGE:
|
2018-12-18 17:52:37 +00:00
|
|
|
return changeColumnParams(state, action.uuid, action.path, action.value);
|
2017-10-08 19:47:15 +00:00
|
|
|
case EMOJI_USE:
|
|
|
|
return updateFrequentEmojis(state, action.emoji);
|
2022-05-16 09:18:35 +00:00
|
|
|
case LANGUAGE_USE:
|
|
|
|
return updateFrequentLanguages(state, action.language);
|
2017-10-08 19:47:15 +00:00
|
|
|
case SETTING_SAVE:
|
|
|
|
return state.set('saved', true);
|
2017-12-09 02:13:08 +00:00
|
|
|
case LIST_FETCH_FAIL:
|
|
|
|
return action.error.response.status === 404 ? filterDeadListColumns(state, action.id) : state;
|
|
|
|
case LIST_DELETE_SUCCESS:
|
|
|
|
return filterDeadListColumns(state, action.id);
|
2017-01-09 13:00:55 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2023-02-03 19:52:07 +00:00
|
|
|
}
|