logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

settings.js (3057B)


  1. import { SETTING_CHANGE, SETTING_SAVE } from '../actions/settings';
  2. import { COLUMN_ADD, COLUMN_REMOVE, COLUMN_MOVE } from '../actions/columns';
  3. import { STORE_HYDRATE } from '../actions/store';
  4. import { EMOJI_USE } from '../actions/emojis';
  5. import { Map as ImmutableMap, fromJS } from 'immutable';
  6. import uuid from '../uuid';
  7. const initialState = ImmutableMap({
  8. saved: true,
  9. onboarded: false,
  10. skinTone: 1,
  11. home: ImmutableMap({
  12. shows: ImmutableMap({
  13. reblog: true,
  14. reply: true,
  15. }),
  16. regex: ImmutableMap({
  17. body: '',
  18. }),
  19. }),
  20. notifications: ImmutableMap({
  21. alerts: ImmutableMap({
  22. follow: true,
  23. favourite: true,
  24. reblog: true,
  25. mention: true,
  26. }),
  27. shows: ImmutableMap({
  28. follow: true,
  29. favourite: true,
  30. reblog: true,
  31. mention: true,
  32. }),
  33. sounds: ImmutableMap({
  34. follow: true,
  35. favourite: true,
  36. reblog: true,
  37. mention: true,
  38. }),
  39. }),
  40. community: ImmutableMap({
  41. regex: ImmutableMap({
  42. body: '',
  43. }),
  44. }),
  45. public: ImmutableMap({
  46. regex: ImmutableMap({
  47. body: '',
  48. }),
  49. }),
  50. });
  51. const defaultColumns = fromJS([
  52. { id: 'COMPOSE', uuid: uuid(), params: {} },
  53. { id: 'HOME', uuid: uuid(), params: {} },
  54. { id: 'NOTIFICATIONS', uuid: uuid(), params: {} },
  55. ]);
  56. const hydrate = (state, settings) => state.mergeDeep(settings).update('columns', (val = defaultColumns) => val);
  57. const moveColumn = (state, uuid, direction) => {
  58. const columns = state.get('columns');
  59. const index = columns.findIndex(item => item.get('uuid') === uuid);
  60. const newIndex = index + direction;
  61. let newColumns;
  62. newColumns = columns.splice(index, 1);
  63. newColumns = newColumns.splice(newIndex, 0, columns.get(index));
  64. return state
  65. .set('columns', newColumns)
  66. .set('saved', false);
  67. };
  68. const updateFrequentEmojis = (state, emoji) => state.update('frequentlyUsedEmojis', ImmutableMap(), map => map.update(emoji.id, 0, count => count + 1)).set('saved', false);
  69. const filterDeadListColumns = (state, listId) => state.update('columns', columns => columns.filterNot(column => column.get('id') === 'LIST' && column.get('params').get('id') === listId));
  70. export default function settings(state = initialState, action) {
  71. switch(action.type) {
  72. case STORE_HYDRATE:
  73. return hydrate(state, action.state.get('settings'));
  74. case SETTING_CHANGE:
  75. return state
  76. .setIn(action.path, action.value)
  77. .set('saved', false);
  78. case COLUMN_ADD:
  79. return state
  80. .update('columns', list => list.push(fromJS({ id: action.id, uuid: uuid(), params: action.params })))
  81. .set('saved', false);
  82. case COLUMN_REMOVE:
  83. return state
  84. .update('columns', list => list.filterNot(item => item.get('uuid') === action.uuid))
  85. .set('saved', false);
  86. case COLUMN_MOVE:
  87. return moveColumn(state, action.uuid, action.direction);
  88. case EMOJI_USE:
  89. return updateFrequentEmojis(state, action.emoji);
  90. case SETTING_SAVE:
  91. return state.set('saved', true);
  92. default:
  93. return state;
  94. }
  95. };