Selaa lähdekoodia

feat(external_api) add event for chat updates (unread counter, open state)

master
Tudor-Ovidiu Avram 4 vuotta sitten
vanhempi
commit
dcaad41e69

+ 15
- 0
modules/API/API.js Näytä tiedosto

556
         }
556
         }
557
     }
557
     }
558
 
558
 
559
+    /**
560
+     * Notify external application (if API is enabled) that the chat state has been updated.
561
+     *
562
+     * @param {number} unreadCount - The unread messages counter.
563
+     * @param {boolean} isOpen - True if the chat panel is open.
564
+     * @returns {void}
565
+     */
566
+    notifyChatUpdated(unreadCount: number, isOpen: boolean) {
567
+        this._sendEvent({
568
+            name: 'chat-updated',
569
+            unreadCount,
570
+            isOpen
571
+        });
572
+    }
573
+
559
     /**
574
     /**
560
      * Notify external application (if API is enabled) that message was sent.
575
      * Notify external application (if API is enabled) that message was sent.
561
      *
576
      *

+ 7
- 0
modules/API/external/external_api.js Näytä tiedosto

64
     'audio-availability-changed': 'audioAvailabilityChanged',
64
     'audio-availability-changed': 'audioAvailabilityChanged',
65
     'audio-mute-status-changed': 'audioMuteStatusChanged',
65
     'audio-mute-status-changed': 'audioMuteStatusChanged',
66
     'camera-error': 'cameraError',
66
     'camera-error': 'cameraError',
67
+    'chat-updated': 'chatUpdated',
67
     'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
68
     'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
68
     'device-list-changed': 'deviceListChanged',
69
     'device-list-changed': 'deviceListChanged',
69
     'display-name-change': 'displayNameChange',
70
     'display-name-change': 'displayNameChange',
572
      * logLevel: the message log level
573
      * logLevel: the message log level
573
      * arguments: an array of strings that compose the actual log message
574
      * arguments: an array of strings that compose the actual log message
574
      * }}
575
      * }}
576
+     * {@code chatUpdated} - receives event notifications about chat state being
577
+     * updated. The listener will receive object with the following structure:
578
+     * {{
579
+     *  'unreadCount': unreadCounter, // the unread message(s) counter,
580
+     *  'isOpen': isOpen, // whether the chat panel is open or not
581
+     * }}
575
      * {@code incomingMessage} - receives event notifications about incoming
582
      * {@code incomingMessage} - receives event notifications about incoming
576
      * messages. The listener will receive object with the following structure:
583
      * messages. The listener will receive object with the following structure:
577
      * {{
584
      * {{

+ 20
- 2
react/features/chat/middleware.js Näytä tiedosto

20
 import { playSound, registerSound, unregisterSound } from '../base/sounds';
20
 import { playSound, registerSound, unregisterSound } from '../base/sounds';
21
 import { showToolbox } from '../toolbox/actions';
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
 import { addMessage, clearMessages, toggleChat } from './actions';
24
 import { addMessage, clearMessages, toggleChat } from './actions';
25
 import { ChatPrivacyDialog } from './components';
25
 import { ChatPrivacyDialog } from './components';
26
 import {
26
 import {
30
     MESSAGE_TYPE_LOCAL,
30
     MESSAGE_TYPE_LOCAL,
31
     MESSAGE_TYPE_REMOTE
31
     MESSAGE_TYPE_REMOTE
32
 } from './constants';
32
 } from './constants';
33
+import { getUnreadCount } from './functions';
33
 import { INCOMING_MSG_SOUND_FILE } from './sounds';
34
 import { INCOMING_MSG_SOUND_FILE } from './sounds';
34
 
35
 
35
 declare var APP: Object;
36
 declare var APP: Object;
50
  * @returns {Function}
51
  * @returns {Function}
51
  */
52
  */
52
 MiddlewareRegistry.register(store => next => action => {
53
 MiddlewareRegistry.register(store => next => action => {
53
-    const { dispatch } = store;
54
+    const { dispatch, getState } = store;
55
+    let isOpen, unreadCount;
54
 
56
 
55
     switch (action.type) {
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
     case APP_WILL_MOUNT:
74
     case APP_WILL_MOUNT:
57
         dispatch(
75
         dispatch(
58
                 registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));
76
                 registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_FILE));

Loading…
Peruuta
Tallenna