Преглед на файлове

ref(notifications): move join notification firing to notifications feature

master
Leonard Kim преди 6 години
родител
ревизия
979b773c3c

+ 0
- 72
react/features/base/participants/actions.js Целия файл

@@ -1,5 +1,3 @@
1
-import throttle from 'lodash/throttle';
2
-
3 1
 import { set } from '../redux';
4 2
 import { NOTIFICATION_TIMEOUT, showNotification } from '../../notifications';
5 3
 
@@ -449,73 +447,3 @@ export function pinParticipant(id) {
449 447
         }
450 448
     };
451 449
 }
452
-
453
-/**
454
- * An array of names of participants that have joined the conference. The array
455
- * is replaced with an empty array as notifications are displayed.
456
- *
457
- * @private
458
- * @type {string[]}
459
- */
460
-let joinedParticipantsNames = [];
461
-
462
-/**
463
- * A throttled internal function that takes the internal list of participant
464
- * names, {@code joinedParticipantsNames}, and triggers the display of a
465
- * notification informing of their joining.
466
- *
467
- * @private
468
- * @type {Function}
469
- */
470
-const _throttledNotifyParticipantConnected = throttle(dispatch => {
471
-    const joinedParticipantsCount = joinedParticipantsNames.length;
472
-
473
-    let notificationProps;
474
-
475
-    if (joinedParticipantsCount >= 3) {
476
-        notificationProps = {
477
-            titleArguments: {
478
-                name: joinedParticipantsNames[0],
479
-                count: joinedParticipantsCount - 1
480
-            },
481
-            titleKey: 'notify.connectedThreePlusMembers'
482
-        };
483
-    } else if (joinedParticipantsCount === 2) {
484
-        notificationProps = {
485
-            titleArguments: {
486
-                first: joinedParticipantsNames[0],
487
-                second: joinedParticipantsNames[1]
488
-            },
489
-            titleKey: 'notify.connectedTwoMembers'
490
-        };
491
-    } else if (joinedParticipantsCount) {
492
-        notificationProps = {
493
-            titleArguments: {
494
-                name: joinedParticipantsNames[0]
495
-            },
496
-            titleKey: 'notify.connectedOneMember'
497
-        };
498
-    }
499
-
500
-    if (notificationProps) {
501
-        dispatch(
502
-            showNotification(notificationProps, NOTIFICATION_TIMEOUT));
503
-    }
504
-
505
-    joinedParticipantsNames = [];
506
-
507
-}, 500, { leading: false });
508
-
509
-/**
510
- * Queues the display of a notification of a participant having connected to
511
- * the meeting. The notifications are batched so that quick consecutive
512
- * connection events are shown in one notification.
513
- *
514
- * @param {string} displayName - The name of the participant that connected.
515
- * @returns {Function}
516
- */
517
-export function showParticipantJoinedNotification(displayName) {
518
-    joinedParticipantsNames.push(displayName);
519
-
520
-    return dispatch => _throttledNotifyParticipantConnected(dispatch);
521
-}

+ 2
- 11
react/features/base/participants/middleware.js Целия файл

@@ -20,8 +20,7 @@ import {
20 20
     localParticipantJoined,
21 21
     localParticipantLeft,
22 22
     participantLeft,
23
-    participantUpdated,
24
-    showParticipantJoinedNotification
23
+    participantUpdated
25 24
 } from './actions';
26 25
 import {
27 26
     DOMINANT_SPEAKER_CHANGED,
@@ -118,15 +117,7 @@ MiddlewareRegistry.register(store => next => action => {
118 117
     case PARTICIPANT_JOINED: {
119 118
         _maybePlaySounds(store, action);
120 119
 
121
-        const result = _participantJoinedOrUpdated(store, next, action);
122
-
123
-        const { participant: p } = action;
124
-
125
-        if (!p.local) {
126
-            store.dispatch(showParticipantJoinedNotification(getParticipantDisplayName(store.getState, p.id)));
127
-        }
128
-
129
-        return result;
120
+        return _participantJoinedOrUpdated(store, next, action);
130 121
     }
131 122
 
132 123
     case PARTICIPANT_LEFT:

+ 75
- 1
react/features/notifications/actions.js Целия файл

@@ -1,5 +1,9 @@
1 1
 // @flow
2 2
 
3
+import throttle from 'lodash/throttle';
4
+
5
+import type { Dispatch } from 'redux';
6
+
3 7
 import {
4 8
     CLEAR_NOTIFICATIONS,
5 9
     HIDE_NOTIFICATION,
@@ -7,7 +11,7 @@ import {
7 11
     SHOW_NOTIFICATION
8 12
 } from './actionTypes';
9 13
 
10
-import { NOTIFICATION_TYPE } from './constants';
14
+import { NOTIFICATION_TIMEOUT, NOTIFICATION_TYPE } from './constants';
11 15
 
12 16
 /**
13 17
  * Clears (removes) all the notifications.
@@ -102,3 +106,73 @@ export function showWarningNotification(props: Object) {
102 106
         appearance: NOTIFICATION_TYPE.WARNING
103 107
     });
104 108
 }
109
+
110
+/**
111
+ * An array of names of participants that have joined the conference. The array
112
+ * is replaced with an empty array as notifications are displayed.
113
+ *
114
+ * @private
115
+ * @type {string[]}
116
+ */
117
+let joinedParticipantsNames = [];
118
+
119
+/**
120
+ * A throttled internal function that takes the internal list of participant
121
+ * names, {@code joinedParticipantsNames}, and triggers the display of a
122
+ * notification informing of their joining.
123
+ *
124
+ * @private
125
+ * @type {Function}
126
+ */
127
+const _throttledNotifyParticipantConnected = throttle((dispatch: Dispatch<any>) => {
128
+    const joinedParticipantsCount = joinedParticipantsNames.length;
129
+
130
+    let notificationProps;
131
+
132
+    if (joinedParticipantsCount >= 3) {
133
+        notificationProps = {
134
+            titleArguments: {
135
+                name: joinedParticipantsNames[0],
136
+                count: joinedParticipantsCount - 1
137
+            },
138
+            titleKey: 'notify.connectedThreePlusMembers'
139
+        };
140
+    } else if (joinedParticipantsCount === 2) {
141
+        notificationProps = {
142
+            titleArguments: {
143
+                first: joinedParticipantsNames[0],
144
+                second: joinedParticipantsNames[1]
145
+            },
146
+            titleKey: 'notify.connectedTwoMembers'
147
+        };
148
+    } else if (joinedParticipantsCount) {
149
+        notificationProps = {
150
+            titleArguments: {
151
+                name: joinedParticipantsNames[0]
152
+            },
153
+            titleKey: 'notify.connectedOneMember'
154
+        };
155
+    }
156
+
157
+    if (notificationProps) {
158
+        dispatch(
159
+            showNotification(notificationProps, NOTIFICATION_TIMEOUT));
160
+    }
161
+
162
+    joinedParticipantsNames = [];
163
+
164
+}, 500, { leading: false });
165
+
166
+/**
167
+ * Queues the display of a notification of a participant having connected to
168
+ * the meeting. The notifications are batched so that quick consecutive
169
+ * connection events are shown in one notification.
170
+ *
171
+ * @param {string} displayName - The name of the participant that connected.
172
+ * @returns {Function}
173
+ */
174
+export function showParticipantJoinedNotification(displayName: string) {
175
+    joinedParticipantsNames.push(displayName);
176
+
177
+    return (dispatch: Dispatch<any>) => _throttledNotifyParticipantConnected(dispatch);
178
+}

+ 33
- 2
react/features/notifications/middleware.js Целия файл

@@ -1,9 +1,40 @@
1 1
 /* @flow */
2 2
 
3 3
 import { getCurrentConference } from '../base/conference';
4
-import { StateListenerRegistry } from '../base/redux';
4
+import {
5
+    PARTICIPANT_JOINED,
6
+    getParticipantDisplayName
7
+} from '../base/participants';
8
+import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
5 9
 
6
-import { clearNotifications } from './actions';
10
+import {
11
+    clearNotifications,
12
+    showParticipantJoinedNotification
13
+} from './actions';
14
+
15
+/**
16
+ * Middleware that captures actions to display notifications.
17
+ *
18
+ * @param {Store} store - The redux store.
19
+ * @returns {Function}
20
+ */
21
+MiddlewareRegistry.register(store => next => action => {
22
+    const result = next(action);
23
+
24
+    switch (action.type) {
25
+    case PARTICIPANT_JOINED: {
26
+        const { participant: p } = action;
27
+
28
+        if (!p.local) {
29
+            store.dispatch(showParticipantJoinedNotification(
30
+                getParticipantDisplayName(store.getState, p.id)
31
+            ));
32
+        }
33
+    }
34
+    }
35
+
36
+    return result;
37
+});
7 38
 
8 39
 /**
9 40
  * StateListenerRegistry provides a reliable way to detect the leaving of a

Loading…
Отказ
Запис