2017-10-08 22:47:15 +03:00
|
|
|
import { SETTING_CHANGE, SETTING_SAVE } from '../actions/settings';
|
2018-12-16 06:56:41 +02:00
|
|
|
import { NOTIFICATIONS_FILTER_SET } from '../actions/notifications';
|
2018-05-22 14:26:06 +03:00
|
|
|
import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE, COLUMN_PARAMS_CHANGE } from '../actions/columns';
|
2017-01-09 15:00:55 +02:00
|
|
|
import { STORE_HYDRATE } from '../actions/store';
|
2017-10-08 22:47:15 +03:00
|
|
|
import { EMOJI_USE } from '../actions/emojis';
|
2017-12-06 00:02:27 +02:00
|
|
|
import { LIST_DELETE_SUCCESS, LIST_FETCH_FAIL } from '../actions/lists';
|
2017-07-11 02:00:14 +03:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
2017-06-04 02:39:38 +03:00
|
|
|
import uuid from '../uuid';
|
2017-01-09 15:00:55 +02:00
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
const initialState = ImmutableMap({
|
2017-10-08 22:47:15 +03:00
|
|
|
saved: true,
|
|
|
|
|
2017-10-07 20:02:30 +03:00
|
|
|
skinTone: 1,
|
|
|
|
|
2019-08-06 18:57:52 +03:00
|
|
|
trends: ImmutableMap({
|
|
|
|
show: true,
|
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
home: ImmutableMap({
|
|
|
|
shows: ImmutableMap({
|
2017-01-10 18:25:10 +02:00
|
|
|
reblog: true,
|
2017-05-20 18:31:47 +03:00
|
|
|
reply: true,
|
2017-05-03 03:04:16 +03:00
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
regex: ImmutableMap({
|
2017-05-20 18:31:47 +03:00
|
|
|
body: '',
|
|
|
|
}),
|
2017-01-10 18:25:10 +02:00
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
notifications: ImmutableMap({
|
|
|
|
alerts: ImmutableMap({
|
2020-10-13 01:37:21 +03:00
|
|
|
follow: false,
|
2019-12-01 18:25:29 +02:00
|
|
|
follow_request: false,
|
2020-10-13 01:37:21 +03:00
|
|
|
favourite: false,
|
|
|
|
reblog: false,
|
|
|
|
mention: false,
|
|
|
|
poll: false,
|
2020-10-15 17:24:47 +03:00
|
|
|
status: false,
|
2017-01-09 15:00:55 +02:00
|
|
|
}),
|
|
|
|
|
2018-12-16 06:56:41 +02:00
|
|
|
quickFilter: ImmutableMap({
|
|
|
|
active: 'all',
|
|
|
|
show: true,
|
|
|
|
advanced: false,
|
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
shows: ImmutableMap({
|
2017-01-09 15:00:55 +02:00
|
|
|
follow: true,
|
2019-12-01 18:25:29 +02:00
|
|
|
follow_request: false,
|
2017-01-09 15:00:55 +02:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 18:31:47 +03:00
|
|
|
mention: true,
|
2019-03-11 01:49:31 +02:00
|
|
|
poll: true,
|
2020-10-15 17:24:47 +03:00
|
|
|
status: true,
|
2017-01-17 21:09:03 +02:00
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
sounds: ImmutableMap({
|
2017-01-17 21:09:03 +02:00
|
|
|
follow: true,
|
2019-12-01 18:25:29 +02:00
|
|
|
follow_request: false,
|
2017-01-17 21:09:03 +02:00
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-20 18:31:47 +03:00
|
|
|
mention: true,
|
2019-03-11 01:49:31 +02:00
|
|
|
poll: true,
|
2020-10-15 17:24:47 +03:00
|
|
|
status: true,
|
2017-05-20 18:31:47 +03:00
|
|
|
}),
|
2017-06-06 17:56:10 +03:00
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
community: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
2017-06-06 17:56:10 +03:00
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
public: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
2017-06-06 17:56:10 +03:00
|
|
|
body: '',
|
|
|
|
}),
|
2017-05-20 18:31:47 +03:00
|
|
|
}),
|
2018-04-18 14:09:06 +03:00
|
|
|
|
|
|
|
direct: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
2017-01-09 15:00:55 +02:00
|
|
|
});
|
|
|
|
|
2017-07-11 02:00:14 +03:00
|
|
|
const defaultColumns = fromJS([
|
2017-06-14 22:59:52 +03:00
|
|
|
{ id: 'COMPOSE', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'HOME', uuid: uuid(), params: {} },
|
|
|
|
{ id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
|
|
|
|
]);
|
|
|
|
|
2017-06-15 00:07:06 +03:00
|
|
|
const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
|
2017-06-14 22:59:52 +03:00
|
|
|
|
2017-06-04 02:39:38 +03: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 22:47:15 +03:00
|
|
|
return state
|
|
|
|
.set('columns', newColumns)
|
|
|
|
.set('saved', false);
|
2017-06-04 02:39:38 +03:00
|
|
|
};
|
|
|
|
|
2018-06-15 12:15:15 +03:00
|
|
|
const changeColumnParams = (state, uuid, path, value) => {
|
2018-05-22 14:26:06 +03:00
|
|
|
const columns = state.get('columns');
|
|
|
|
const index = columns.findIndex(item => item.get('uuid') === uuid);
|
|
|
|
|
2018-06-15 12:15:15 +03:00
|
|
|
const newColumns = columns.update(index, column => column.updateIn(['params', ...path], () => value));
|
2018-05-22 14:26:06 +03:00
|
|
|
|
|
|
|
return state
|
|
|
|
.set('columns', newColumns)
|
|
|
|
.set('saved', false);
|
|
|
|
};
|
|
|
|
|
2017-10-08 22:47:15 +03:00
|
|
|
const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false);
|
|
|
|
|
2017-12-06 00:02:27 +02: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 15:00:55 +02:00
|
|
|
export default function settings(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case STORE_HYDRATE:
|
2017-06-15 00:07:06 +03:00
|
|
|
return hydrate(state, action.state.get('settings'));
|
2018-12-16 06:56:41 +02:00
|
|
|
case NOTIFICATIONS_FILTER_SET:
|
2017-01-09 15:00:55 +02:00
|
|
|
case SETTING_CHANGE:
|
2017-10-08 22:47:15 +03:00
|
|
|
return state
|
2018-01-02 14:50:54 +02:00
|
|
|
.setIn(action.path, action.value)
|
2017-10-08 22:47:15 +03:00
|
|
|
.set('saved', false);
|
2017-06-04 02:39:38 +03:00
|
|
|
case COLUMN_ADD:
|
2017-10-08 22:47:15 +03:00
|
|
|
return state
|
|
|
|
.update('columns', list => list.push(fromJS({ id: action.id, uuid: uuid(), params: action.params })))
|
|
|
|
.set('saved', false);
|
2017-06-04 02:39:38 +03:00
|
|
|
case COLUMN_REMOVE:
|
2017-10-08 22:47:15 +03:00
|
|
|
return state
|
|
|
|
.update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid))
|
|
|
|
.set('saved', false);
|
2017-06-04 02:39:38 +03:00
|
|
|
case COLUMN_MOVE:
|
|
|
|
return moveColumn(state, action.uuid, action.direction);
|
2018-05-22 14:26:06 +03:00
|
|
|
case COLUMN_PARAMS_CHANGE:
|
2018-06-15 12:15:15 +03:00
|
|
|
return changeColumnParams(state, action.uuid, action.path, action.value);
|
2017-10-08 22:47:15 +03:00
|
|
|
case EMOJI_USE:
|
|
|
|
return updateFrequentEmojis(state, action.emoji);
|
|
|
|
case SETTING_SAVE:
|
|
|
|
return state.set('saved', true);
|
2017-12-06 00:02:27 +02: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 15:00:55 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|