2017-12-04 16:26:40 +09:00
|
|
|
import { SETTING_CHANGE, SETTING_SAVE } from 'flavours/glitch/actions/settings';
|
|
|
|
import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from 'flavours/glitch/actions/columns';
|
|
|
|
import { STORE_HYDRATE } from 'flavours/glitch/actions/store';
|
|
|
|
import { EMOJI_USE } from 'flavours/glitch/actions/emojis';
|
2017-07-11 08:00:14 +09:00
|
|
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
2017-12-04 16:26:40 +09:00
|
|
|
import uuid from 'flavours/glitch/util/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-04-17 03:32:00 +09:00
|
|
|
onboarded: false,
|
2017-06-25 09:07:25 +09:00
|
|
|
layout: 'auto',
|
2017-04-17 03:32:00 +09:00
|
|
|
|
2017-10-08 02:02:30 +09:00
|
|
|
skinTone: 1,
|
|
|
|
|
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({
|
2017-01-09 22:00:55 +09:00
|
|
|
follow: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-21 00:31:47 +09:00
|
|
|
mention: true,
|
2017-01-09 22:00:55 +09:00
|
|
|
}),
|
|
|
|
|
2017-07-11 08:00:14 +09:00
|
|
|
shows: ImmutableMap({
|
2017-01-09 22:00:55 +09:00
|
|
|
follow: true,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-21 00:31:47 +09:00
|
|
|
mention: 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,
|
|
|
|
favourite: true,
|
|
|
|
reblog: true,
|
2017-05-21 00:31:47 +09:00
|
|
|
mention: true,
|
|
|
|
}),
|
2017-06-06 23:56:10 +09:00
|
|
|
}),
|
|
|
|
|
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
|
|
|
}),
|
2017-10-16 13:02:39 +09:00
|
|
|
|
|
|
|
direct: ImmutableMap({
|
|
|
|
regex: ImmutableMap({
|
|
|
|
body: '',
|
|
|
|
}),
|
|
|
|
}),
|
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
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
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'));
|
2017-01-09 22:00:55 +09:00
|
|
|
case SETTING_CHANGE:
|
2017-10-09 04:47:15 +09:00
|
|
|
return state
|
|
|
|
.setIn(action.key, action.value)
|
|
|
|
.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);
|
2017-10-09 04:47:15 +09:00
|
|
|
case EMOJI_USE:
|
|
|
|
return updateFrequentEmojis(state, action.emoji);
|
|
|
|
case SETTING_SAVE:
|
|
|
|
return state.set('saved', true);
|
2017-01-09 22:00:55 +09:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|