forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.js
More file actions
49 lines (43 loc) · 1 KB
/
message.js
File metadata and controls
49 lines (43 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as types from '../constants/ActionTypes';
const initialState = {
hasNotRead: [],
hasRead: [],
unreadMessageCount: 0
};
export default function (state = initialState, action) {
const { payload, error, meta = {} } = action;
const { sequence = {} } = meta;
if (sequence.type === 'start' || error) {
return state;
}
switch (action.type) {
case types.GET_MESSAGES_LIST:
return {
...state,
unreadMessageCount: payload.hasnot_read_messages.length,
hasRead: payload.has_read_messages,
hasNotRead: payload.hasnot_read_messages
};
case types.GET_REDUCER_FROM_ASYNC_STORAGE:
return {
...state,
...payload.message || initialState
};
case types.GET_UNREAD_MESSAGE_COUNT:
return {
...state,
unreadMessageCount: payload
};
case types.MARK_AS_READ:
return {
...state,
hasNotRead: [],
hasRead: state.hasNotRead.concat(state.hasRead),
unreadMessageCount: 0
};
case types.LOGOUT:
return initialState;
default :
return state;
}
}