Procházet zdrojové kódy

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

j8
Tudor-Ovidiu Avram před 4 roky
rodič
revize
dcaad41e69

+ 15
- 0
modules/API/API.js Zobrazit soubor

@@ -556,6 +556,21 @@ class API {
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 575
      * Notify external application (if API is enabled) that message was sent.
561 576
      *

+ 7
- 0
modules/API/external/external_api.js Zobrazit soubor

@@ -64,6 +64,7 @@ const events = {
64 64
     'audio-availability-changed': 'audioAvailabilityChanged',
65 65
     'audio-mute-status-changed': 'audioMuteStatusChanged',
66 66
     'camera-error': 'cameraError',
67
+    'chat-updated': 'chatUpdated',
67 68
     'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
68 69
     'device-list-changed': 'deviceListChanged',
69 70
     'display-name-change': 'displayNameChange',
@@ -572,6 +573,12 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
572 573
      * logLevel: the message log level
573 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 582
      * {@code incomingMessage} - receives event notifications about incoming
576 583
      * messages. The listener will receive object with the following structure:
577 584
      * {{

+ 20
- 2
react/features/chat/middleware.js Zobrazit soubor

@@ -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));

Načítá se…
Zrušit
Uložit