You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
713 B

  1. import { Map as ImmutableMap } from 'immutable';
  2. import { NOTIFICATIONS_UPDATE } from 'mastodon/actions/notifications';
  3. import { TIMELINE_UPDATE } from 'mastodon/actions/timelines';
  4. import { APP_FOCUS, APP_UNFOCUS } from 'mastodon/actions/app';
  5. const initialState = ImmutableMap({
  6. focused: true,
  7. unread: 0,
  8. });
  9. export default function missed_updates(state = initialState, action) {
  10. switch(action.type) {
  11. case APP_FOCUS:
  12. return state.set('focused', true).set('unread', 0);
  13. case APP_UNFOCUS:
  14. return state.set('focused', false);
  15. case NOTIFICATIONS_UPDATE:
  16. case TIMELINE_UPDATE:
  17. return state.get('focused') ? state : state.update('unread', x => x + 1);
  18. default:
  19. return state;
  20. }
  21. };