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