Просмотр исходного кода

feat(participants): add isLocalParticipantModerator utility method

j8
Zoltan Bettenbuk 7 лет назад
Родитель
Сommit
b57dad576a

+ 27
- 1
react/features/base/participants/functions.js Просмотреть файл

@@ -5,7 +5,8 @@ import { toState } from '../redux';
5 5
 
6 6
 import {
7 7
     DEFAULT_AVATAR_RELATIVE_PATH,
8
-    LOCAL_PARTICIPANT_DEFAULT_ID
8
+    LOCAL_PARTICIPANT_DEFAULT_ID,
9
+    PARTICIPANT_ROLE
9 10
 } from './constants';
10 11
 
11 12
 declare var config: Object;
@@ -224,3 +225,28 @@ function _getAllParticipants(stateful) {
224 225
             ? stateful
225 226
             : toState(stateful)['features/base/participants'] || []);
226 227
 }
228
+
229
+/**
230
+ * Returns true if the current local participant is a moderator in the
231
+ * conference.
232
+ *
233
+ * @param {Object|Function} stateful - Object or function that can be resolved
234
+ * to the Redux state.
235
+ * @returns {boolean}
236
+ */
237
+export function isLocalParticipantModerator(stateful: Object | Function) {
238
+    const state = toState(stateful);
239
+    const localParticipant = getLocalParticipant(state);
240
+
241
+    if (!localParticipant) {
242
+        return false;
243
+    }
244
+
245
+    const isModerator = localParticipant.role === PARTICIPANT_ROLE.MODERATOR;
246
+
247
+    if (state['features/base/config'].enableUserRolesBasedOnToken) {
248
+        return isModerator && !state['features/base/jwt'].isGuest;
249
+    }
250
+
251
+    return isModerator;
252
+}

+ 2
- 14
react/features/invite/components/info-dialog/InfoDialog.web.js Просмотреть файл

@@ -5,10 +5,7 @@ import { connect } from 'react-redux';
5 5
 import { setPassword } from '../../../base/conference';
6 6
 import { getInviteURL } from '../../../base/connection';
7 7
 import { translate } from '../../../base/i18n';
8
-import {
9
-    PARTICIPANT_ROLE,
10
-    getLocalParticipant
11
-} from '../../../base/participants';
8
+import { isLocalParticipantModerator } from '../../../base/participants';
12 9
 
13 10
 import DialInNumber from './DialInNumber';
14 11
 import PasswordForm from './PasswordForm';
@@ -553,18 +550,9 @@ function _mapStateToProps(state) {
553 550
         password,
554 551
         room
555 552
     } = state['features/base/conference'];
556
-    const isModerator
557
-        = getLocalParticipant(state).role === PARTICIPANT_ROLE.MODERATOR;
558
-    let canEditPassword;
559
-
560
-    if (state['features/base/config'].enableUserRolesBasedOnToken) {
561
-        canEditPassword = isModerator && !state['features/base/jwt'].isGuest;
562
-    } else {
563
-        canEditPassword = isModerator;
564
-    }
565 553
 
566 554
     return {
567
-        _canEditPassword: canEditPassword,
555
+        _canEditPassword: isLocalParticipantModerator(state),
568 556
         _conference: conference,
569 557
         _conferenceName: room,
570 558
         _inviteURL: getInviteURL(state),

+ 4
- 8
react/features/invite/functions.js Просмотреть файл

@@ -1,7 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { getAppProp } from '../app';
4
-import { getLocalParticipant, PARTICIPANT_ROLE } from '../base/participants';
4
+import { isLocalParticipantModerator } from '../base/participants';
5 5
 import { doGetJSON } from '../base/util';
6 6
 
7 7
 declare var $: Function;
@@ -300,14 +300,10 @@ export function isAddPeopleEnabled(state: Object): boolean {
300 300
  * @returns {boolean} Indication of whether dial out is currently enabled.
301 301
  */
302 302
 export function isDialOutEnabled(state: Object): boolean {
303
-    const participant = getLocalParticipant(state);
304 303
     const { conference } = state['features/base/conference'];
305
-    const { isGuest } = state['features/base/jwt'];
306
-    const { enableUserRolesBasedOnToken } = state['features/base/config'];
307
-    let dialOutEnabled
308
-        = participant && participant.role === PARTICIPANT_ROLE.MODERATOR
309
-            && conference && conference.isSIPCallingSupported()
310
-            && (!enableUserRolesBasedOnToken || !isGuest);
304
+    let dialOutEnabled = isLocalParticipantModerator(state)
305
+        && conference
306
+        && conference.isSIPCallingSupported();
311 307
 
312 308
     if (dialOutEnabled) {
313 309
         // XXX The mobile/react-native app is capable of disabling of dial-out.

Загрузка…
Отмена
Сохранить