Browse Source

feat(participants): add isLocalParticipantModerator utility method

master
Zoltan Bettenbuk 7 years ago
parent
commit
b57dad576a

+ 27
- 1
react/features/base/participants/functions.js View File

5
 
5
 
6
 import {
6
 import {
7
     DEFAULT_AVATAR_RELATIVE_PATH,
7
     DEFAULT_AVATAR_RELATIVE_PATH,
8
-    LOCAL_PARTICIPANT_DEFAULT_ID
8
+    LOCAL_PARTICIPANT_DEFAULT_ID,
9
+    PARTICIPANT_ROLE
9
 } from './constants';
10
 } from './constants';
10
 
11
 
11
 declare var config: Object;
12
 declare var config: Object;
224
             ? stateful
225
             ? stateful
225
             : toState(stateful)['features/base/participants'] || []);
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 View File

5
 import { setPassword } from '../../../base/conference';
5
 import { setPassword } from '../../../base/conference';
6
 import { getInviteURL } from '../../../base/connection';
6
 import { getInviteURL } from '../../../base/connection';
7
 import { translate } from '../../../base/i18n';
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
 import DialInNumber from './DialInNumber';
10
 import DialInNumber from './DialInNumber';
14
 import PasswordForm from './PasswordForm';
11
 import PasswordForm from './PasswordForm';
553
         password,
550
         password,
554
         room
551
         room
555
     } = state['features/base/conference'];
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
     return {
554
     return {
567
-        _canEditPassword: canEditPassword,
555
+        _canEditPassword: isLocalParticipantModerator(state),
568
         _conference: conference,
556
         _conference: conference,
569
         _conferenceName: room,
557
         _conferenceName: room,
570
         _inviteURL: getInviteURL(state),
558
         _inviteURL: getInviteURL(state),

+ 4
- 8
react/features/invite/functions.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { getAppProp } from '../app';
3
 import { getAppProp } from '../app';
4
-import { getLocalParticipant, PARTICIPANT_ROLE } from '../base/participants';
4
+import { isLocalParticipantModerator } from '../base/participants';
5
 import { doGetJSON } from '../base/util';
5
 import { doGetJSON } from '../base/util';
6
 
6
 
7
 declare var $: Function;
7
 declare var $: Function;
300
  * @returns {boolean} Indication of whether dial out is currently enabled.
300
  * @returns {boolean} Indication of whether dial out is currently enabled.
301
  */
301
  */
302
 export function isDialOutEnabled(state: Object): boolean {
302
 export function isDialOutEnabled(state: Object): boolean {
303
-    const participant = getLocalParticipant(state);
304
     const { conference } = state['features/base/conference'];
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
     if (dialOutEnabled) {
308
     if (dialOutEnabled) {
313
         // XXX The mobile/react-native app is capable of disabling of dial-out.
309
         // XXX The mobile/react-native app is capable of disabling of dial-out.

Loading…
Cancel
Save