From 13985cf724fa145f6ffc9b452c17d9ccde221da6 Mon Sep 17 00:00:00 2001 From: Daniel Maike Date: Tue, 1 Dec 2020 14:30:39 -0300 Subject: [PATCH] [FIX] App not prompting join code for password protected channels (#2514) * Adding joinCode parameter Co-authored-by: Vitor Leal Co-authored-by: Fernando Aguilar * Insert join code input Signed-off-by: Vitor.Leal * Add joinCode field on db Signed-off-by: Vitor.Leal * Add label i18 pt-br and en-us Signed-off-by: Vitor.Leal * Add insert join code text Signed-off-by: Vitor.Leal * Fix atribute name Signed-off-by: Vitor.Leal * Add join text Signed-off-by: Vitor.Leal Co-authored-by: Daniel Maike Co-authored-by: Fernando Aguilar * Fix attributes joinCode, joinCodeRequired and pass attribute param in navigation Signed-off-by: Daniel Maike Co-authored-by: Vitor Leal * Fixing attribute joinCodeRequired pass to goRoom Signed-off-by: Daniel Maike * Changed textinput style Signed-off-by: Daniel Maike Co-authored-by: Vitor Leal * Delete not necessary attribute Signed-off-by: Daniel Maike * Fixing input style Co-authored-by: Vitor Leal * Undo unncessary changes * use a join code modal * tests: e2e tests to join protected channel * fix: undo unnecessary change * tests: cancel join code * Remove some tests * Minor fixes Co-authored-by: Vitor Leal Co-authored-by: Fernando Aguilar Co-authored-by: Djorkaeff Alexandre Co-authored-by: youssef-md Co-authored-by: Diego Mello --- app/i18n/locales/en.js | 2 + app/i18n/locales/pt-BR.js | 2 + app/lib/rocketchat.js | 4 +- app/views/DirectoryView/index.js | 3 +- app/views/RoomView/JoinCode.js | 140 ++++++++++++++++++ app/views/RoomView/index.js | 28 +++- e2e/data.js | 4 + e2e/data/data.cloud.js | 4 + e2e/data/data.docker.js | 4 + e2e/helpers/data_setup.js | 30 +++- .../assorted/08-joinprotectedroom.spec.js | 60 ++++++++ 11 files changed, 270 insertions(+), 11 deletions(-) create mode 100644 app/views/RoomView/JoinCode.js create mode 100644 e2e/tests/assorted/08-joinprotectedroom.spec.js diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index d85ad30d33..6feb764f13 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -281,6 +281,8 @@ export default { Invite_Link: 'Invite Link', Invite_users: 'Invite users', Join: 'Join', + Join_Code: 'Join Code', + Insert_Join_Code: 'Insert Join Code', Join_our_open_workspace: 'Join our open workspace', Join_your_workspace: 'Join your workspace', Just_invited_people_can_access_this_channel: 'Just invited people can access this channel', diff --git a/app/i18n/locales/pt-BR.js b/app/i18n/locales/pt-BR.js index 743b64295a..3625120787 100644 --- a/app/i18n/locales/pt-BR.js +++ b/app/i18n/locales/pt-BR.js @@ -270,6 +270,8 @@ export default { Invite_Link: 'Link de Convite', Invite_users: 'Convidar usuários', Join: 'Entrar', + Join_Code: 'Insira o Código da Sala', + Insert_Join_Code: 'Insira o código para entrar na sala', Join_our_open_workspace: 'Entra na nossa workspace pública', Join_your_workspace: 'Entre na sua workspace', Just_invited_people_can_access_this_channel: 'Apenas as pessoas convidadas podem acessar este canal', diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 182fd856d1..5020ee4add 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -705,13 +705,13 @@ const RocketChat = { }); }, - joinRoom(roomId, type) { + joinRoom(roomId, joinCode, type) { // TODO: join code // RC 0.48.0 if (type === 'p') { return this.methodCallWrapper('joinRoom', roomId); } - return this.post('channels.join', { roomId }); + return this.post('channels.join', { roomId, joinCode }); }, triggerBlockAction, triggerSubmitView, diff --git a/app/views/DirectoryView/index.js b/app/views/DirectoryView/index.js index 01788bcc2f..8be78712d0 100644 --- a/app/views/DirectoryView/index.js +++ b/app/views/DirectoryView/index.js @@ -149,8 +149,9 @@ class DirectoryView extends React.Component { this.goRoom({ rid: result.room._id, name: item.username, t: 'd' }); } } else { + const { room } = await RocketChat.getRoomInfo(item._id); this.goRoom({ - rid: item._id, name: item.name, t: 'c', search: true + rid: item._id, name: item.name, joinCodeRequired: room.joinCodeRequired, t: 'c', search: true }); } } diff --git a/app/views/RoomView/JoinCode.js b/app/views/RoomView/JoinCode.js new file mode 100644 index 0000000000..e3639818ba --- /dev/null +++ b/app/views/RoomView/JoinCode.js @@ -0,0 +1,140 @@ +import React, { + useState, + forwardRef, + useImperativeHandle +} from 'react'; +import PropTypes from 'prop-types'; +import { + View, + Text, + StyleSheet, + InteractionManager +} from 'react-native'; +import Modal from 'react-native-modal'; +import { connect } from 'react-redux'; + +import I18n from '../../i18n'; +import Button from '../../containers/Button'; +import TextInput from '../../containers/TextInput'; +import RocketChat from '../../lib/rocketchat'; +import sharedStyles from '../Styles'; + +import { themes } from '../../constants/colors'; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center' + }, + content: { + padding: 16, + width: '100%', + borderRadius: 4 + }, + title: { + fontSize: 16, + paddingBottom: 8, + ...sharedStyles.textBold, + ...sharedStyles.textAlignCenter + }, + button: { + minWidth: 96, + marginBottom: 0 + }, + buttonContainer: { + flexDirection: 'row', + justifyContent: 'space-between' + }, + tablet: { + height: undefined + } +}); + +const JoinCode = React.memo(forwardRef(({ + rid, + t, + onJoin, + isMasterDetail, + theme +}, ref) => { + const [visible, setVisible] = useState(false); + const [error, setError] = useState(false); + const [code, setCode] = useState(''); + + const show = () => setVisible(true); + + const hide = () => setVisible(false); + + const joinRoom = async() => { + try { + await RocketChat.joinRoom(rid, code, t); + onJoin(); + hide(); + } catch (e) { + setError(true); + } + }; + + useImperativeHandle(ref, () => ({ show })); + + return ( + + + + {I18n.t('Insert_Join_Code')} + InteractionManager.runAfterInteractions(() => e?.getNativeRef()?.focus())} + returnKeyType='send' + autoCapitalize='none' + onChangeText={setCode} + onSubmitEditing={joinRoom} + placeholder={I18n.t('Join_Code')} + secureTextEntry + error={error && { error: 'error-code-invalid', reason: I18n.t('Code_or_password_invalid') }} + testID='join-code-input' + /> + +