From b57dad576ae592264d07431597031e5ded2d09ce Mon Sep 17 00:00:00 2001 From: Zoltan Bettenbuk Date: Thu, 17 May 2018 17:45:51 +0200 Subject: [PATCH] feat(participants): add isLocalParticipantModerator utility method --- react/features/base/participants/functions.js | 28 ++++++++++++++++++- .../components/info-dialog/InfoDialog.web.js | 16 ++--------- react/features/invite/functions.js | 12 +++----- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/react/features/base/participants/functions.js b/react/features/base/participants/functions.js index 7392a55f3..64957fca3 100644 --- a/react/features/base/participants/functions.js +++ b/react/features/base/participants/functions.js @@ -5,7 +5,8 @@ import { toState } from '../redux'; import { DEFAULT_AVATAR_RELATIVE_PATH, - LOCAL_PARTICIPANT_DEFAULT_ID + LOCAL_PARTICIPANT_DEFAULT_ID, + PARTICIPANT_ROLE } from './constants'; declare var config: Object; @@ -224,3 +225,28 @@ function _getAllParticipants(stateful) { ? stateful : toState(stateful)['features/base/participants'] || []); } + +/** + * Returns true if the current local participant is a moderator in the + * conference. + * + * @param {Object|Function} stateful - Object or function that can be resolved + * to the Redux state. + * @returns {boolean} + */ +export function isLocalParticipantModerator(stateful: Object | Function) { + const state = toState(stateful); + const localParticipant = getLocalParticipant(state); + + if (!localParticipant) { + return false; + } + + const isModerator = localParticipant.role === PARTICIPANT_ROLE.MODERATOR; + + if (state['features/base/config'].enableUserRolesBasedOnToken) { + return isModerator && !state['features/base/jwt'].isGuest; + } + + return isModerator; +} diff --git a/react/features/invite/components/info-dialog/InfoDialog.web.js b/react/features/invite/components/info-dialog/InfoDialog.web.js index f0f0ac795..97c83a708 100644 --- a/react/features/invite/components/info-dialog/InfoDialog.web.js +++ b/react/features/invite/components/info-dialog/InfoDialog.web.js @@ -5,10 +5,7 @@ import { connect } from 'react-redux'; import { setPassword } from '../../../base/conference'; import { getInviteURL } from '../../../base/connection'; import { translate } from '../../../base/i18n'; -import { - PARTICIPANT_ROLE, - getLocalParticipant -} from '../../../base/participants'; +import { isLocalParticipantModerator } from '../../../base/participants'; import DialInNumber from './DialInNumber'; import PasswordForm from './PasswordForm'; @@ -553,18 +550,9 @@ function _mapStateToProps(state) { password, room } = state['features/base/conference']; - const isModerator - = getLocalParticipant(state).role === PARTICIPANT_ROLE.MODERATOR; - let canEditPassword; - - if (state['features/base/config'].enableUserRolesBasedOnToken) { - canEditPassword = isModerator && !state['features/base/jwt'].isGuest; - } else { - canEditPassword = isModerator; - } return { - _canEditPassword: canEditPassword, + _canEditPassword: isLocalParticipantModerator(state), _conference: conference, _conferenceName: room, _inviteURL: getInviteURL(state), diff --git a/react/features/invite/functions.js b/react/features/invite/functions.js index 3faa4b95b..3ae3447d0 100644 --- a/react/features/invite/functions.js +++ b/react/features/invite/functions.js @@ -1,7 +1,7 @@ // @flow import { getAppProp } from '../app'; -import { getLocalParticipant, PARTICIPANT_ROLE } from '../base/participants'; +import { isLocalParticipantModerator } from '../base/participants'; import { doGetJSON } from '../base/util'; declare var $: Function; @@ -300,14 +300,10 @@ export function isAddPeopleEnabled(state: Object): boolean { * @returns {boolean} Indication of whether dial out is currently enabled. */ export function isDialOutEnabled(state: Object): boolean { - const participant = getLocalParticipant(state); const { conference } = state['features/base/conference']; - const { isGuest } = state['features/base/jwt']; - const { enableUserRolesBasedOnToken } = state['features/base/config']; - let dialOutEnabled - = participant && participant.role === PARTICIPANT_ROLE.MODERATOR - && conference && conference.isSIPCallingSupported() - && (!enableUserRolesBasedOnToken || !isGuest); + let dialOutEnabled = isLocalParticipantModerator(state) + && conference + && conference.isSIPCallingSupported(); if (dialOutEnabled) { // XXX The mobile/react-native app is capable of disabling of dial-out.