import React, { PureComponent } from 'react'; import { Text, TextStyle, View, ViewStyle } from 'react-native'; import { connect } from 'react-redux'; import { IReduxState, IStore } from '../../../../app/types'; import { IJitsiConference } from '../../../../base/conference/reducer'; import { getSecurityUiConfig } from '../../../../base/config/functions.any'; import { MEETING_PASSWORD_ENABLED } from '../../../../base/flags/constants'; import { getFeatureFlag } from '../../../../base/flags/functions'; import { translate } from '../../../../base/i18n/functions'; import JitsiScreen from '../../../../base/modal/components/JitsiScreen'; import { isLocalParticipantModerator } from '../../../../base/participants/functions'; import Button from '../../../../base/ui/components/native/Button'; import Input from '../../../../base/ui/components/native/Input'; import Switch from '../../../../base/ui/components/native/Switch'; import { BUTTON_TYPES } from '../../../../base/ui/constants.native'; import { copyText } from '../../../../base/util/copyText.native'; import { isInBreakoutRoom } from '../../../../breakout-rooms/functions'; import { toggleLobbyMode } from '../../../../lobby/actions.any'; import { endRoomLockRequest, unlockRoom } from '../../../../room-lock/actions'; import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../../../room-lock/constants'; import styles from './styles'; /** * The style of the {@link TextInput} rendered by {@code SecurityDialog}. As it * requests the entry of a password, {@code TextInput} automatically correcting * the entry of the password is a pain to deal with as a user. */ const _TEXT_INPUT_PROPS = { autoCapitalize: 'none', autoCorrect: false }; /** * The type of the React {@code Component} props of {@link SecurityDialog}. */ interface IProps { /** * The JitsiConference which requires a password. */ _conference?: IJitsiConference; /** * Whether the local user is the moderator. */ _isModerator: boolean; /** * State of the lobby mode. */ _lobbyEnabled: boolean; /** * Whether the lobby mode switch is available or not. */ _lobbyModeSwitchVisible: boolean; /** * The value for how the conference is locked (or undefined if not locked) * as defined by room-lock constants. */ _locked?: string; /** * Checks if the conference room is locked or not. */ _lockedConference: boolean; /** * The current known password for the JitsiConference. */ _password?: string; /** * Number of digits used in the room-lock password. */ _passwordNumberOfDigits?: number; /** * Whether setting a room password is available or not. */ _roomPasswordControls: boolean; /** * Redux store dispatch function. */ dispatch: IStore['dispatch']; /** * Invoked to obtain translated strings. */ t: Function; } /** * The type of the React {@code Component} state of {@link SecurityDialog}. */ interface IState { /** * Password added by the participant for room lock. */ passwordInputValue: string; /** * Shows an input or a message. */ showElement: boolean; } /** * Component that renders the security options dialog. * * @returns {React$Element} */ class SecurityDialog extends PureComponent { /** * Instantiates a new {@code SecurityDialog}. * * @inheritdoc */ constructor(props: IProps) { super(props); this.state = { passwordInputValue: '', showElement: props._locked === LOCKED_LOCALLY || false }; this._onChangeText = this._onChangeText.bind(this); this._onCancel = this._onCancel.bind(this); this._onCopy = this._onCopy.bind(this); this._onSubmit = this._onSubmit.bind(this); this._onToggleLobbyMode = this._onToggleLobbyMode.bind(this); this._onAddPassword = this._onAddPassword.bind(this); } /** * Implements {@code SecurityDialog.render}. * * @inheritdoc */ render() { return ( { this._renderLobbyMode() } { this._renderSetRoomPassword() } ); } /** * Renders lobby mode. * * @returns {ReactElement} * @private */ _renderLobbyMode() { const { _lobbyEnabled, _lobbyModeSwitchVisible, t } = this.props; if (!_lobbyModeSwitchVisible) { return null; } return ( { t('lobby.enableDialogText') } { t('lobby.toggleLabel') } ); } /** * Renders setting the password. * * @returns {ReactElement} * @private */ _renderSetRoomPassword() { const { _isModerator, _locked, _lockedConference, _password, _roomPasswordControls, t } = this.props; const { showElement } = this.state; let setPasswordControls; if (!_roomPasswordControls) { return null; } if (_locked && showElement) { setPasswordControls = ( <>