about summary refs log tree commit diff
path: root/app/javascript/mastodon/reducers/missed_updates.js
blob: b71d62d8287a897f8768ab523a3b18ec92f9ce17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Map as ImmutableMap } from 'immutable';
import { NOTIFICATIONS_UPDATE } from 'mastodon/actions/notifications';
import { APP_FOCUS, APP_UNFOCUS } from 'mastodon/actions/app';

const initialState = ImmutableMap({
  focused: true,
  unread: 0,
});

export default function missed_updates(state = initialState, action) {
  switch(action.type) {
  case APP_FOCUS:
    return state.set('focused', true).set('unread', 0);
  case APP_UNFOCUS:
    return state.set('focused', false);
  case NOTIFICATIONS_UPDATE:
    return state.get('focused') ? state : state.update('unread', x => x + 1);
  default:
    return state;
  }
};