|
@@ -20,7 +20,7 @@ import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
20
|
20
|
import { playSound, registerSound, unregisterSound } from '../base/sounds';
|
21
|
21
|
import { showToolbox } from '../toolbox/actions';
|
22
|
22
|
|
23
|
|
-import { SEND_MESSAGE, SET_PRIVATE_MESSAGE_RECIPIENT } from './actionTypes';
|
|
23
|
+import { ADD_MESSAGE, TOGGLE_CHAT, SEND_MESSAGE, SET_PRIVATE_MESSAGE_RECIPIENT } from './actionTypes';
|
24
|
24
|
import { addMessage, clearMessages, toggleChat } from './actions';
|
25
|
25
|
import { ChatPrivacyDialog } from './components';
|
26
|
26
|
import {
|
|
@@ -30,6 +30,7 @@ import {
|
30
|
30
|
MESSAGE_TYPE_LOCAL,
|
31
|
31
|
MESSAGE_TYPE_REMOTE
|
32
|
32
|
} from './constants';
|
|
33
|
+import { getUnreadCount } from './functions';
|
33
|
34
|
import { INCOMING_MSG_SOUND_FILE } from './sounds';
|
34
|
35
|
|
35
|
36
|
declare var APP: Object;
|
|
@@ -50,9 +51,26 @@ const PRIVACY_NOTICE_TIMEOUT = 20 * 1000;
|
50
|
51
|
* @returns {Function}
|
51
|
52
|
*/
|
52
|
53
|
MiddlewareRegistry.register(store => next => action => {
|
53
|
|
- const { dispatch } = store;
|
|
54
|
+ const { dispatch, getState } = store;
|
|
55
|
+ let isOpen, unreadCount;
|
54
|
56
|
|
55
|
57
|
switch (action.type) {
|
|
58
|
+ case ADD_MESSAGE:
|
|
59
|
+ unreadCount = action.hasRead ? 0 : getUnreadCount(getState()) + 1;
|
|
60
|
+ isOpen = getState()['features/chat'].isOpen;
|
|
61
|
+
|
|
62
|
+ if (typeof APP !== 'undefined') {
|
|
63
|
+ APP.API.notifyChatUpdated(unreadCount, isOpen);
|
|
64
|
+ }
|
|
65
|
+ break;
|
|
66
|
+ case TOGGLE_CHAT:
|
|
67
|
+ unreadCount = 0;
|
|
68
|
+ isOpen = !getState()['features/chat'].isOpen;
|
|
69
|
+
|
|
70
|
+ if (typeof APP !== 'undefined') {
|
|
71
|
+ APP.API.notifyChatUpdated(unreadCount, isOpen);
|
|
72
|
+ }
|
|
73
|
+ break;
|
56
|
74
|
case APP_WILL_MOUNT:
|
57
|
75
|
dispatch(
|
58
|
76
|
registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));
|