[FIX] Room Info actions doesn't check permissions/settings enabled (#2292)
* [FIX] Show Call Button only when Jitsi Enabled (RoomInfoView) * [FIX] Show user info * [FIX] Show message button only if it's possible * [FIX] Create direct only when needed Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
fa6897f339
commit
c6401a2d39
|
@ -22,6 +22,8 @@ import { themes } from '../../constants/colors';
|
|||
import { withTheme } from '../../theme';
|
||||
import { getUserSelector } from '../../selectors/login';
|
||||
import Markdown from '../../containers/markdown';
|
||||
import { LISTENER } from '../../containers/Toast';
|
||||
import EventEmitter from '../../utils/events';
|
||||
|
||||
import Livechat from './Livechat';
|
||||
import Channel from './Channel';
|
||||
|
@ -59,7 +61,8 @@ class RoomInfoView extends React.Component {
|
|||
baseUrl: PropTypes.string,
|
||||
rooms: PropTypes.array,
|
||||
theme: PropTypes.string,
|
||||
isMasterDetail: PropTypes.bool
|
||||
isMasterDetail: PropTypes.bool,
|
||||
jitsiEnabled: PropTypes.bool
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
|
@ -167,11 +170,11 @@ class RoomInfoView extends React.Component {
|
|||
}
|
||||
|
||||
loadUser = async() => {
|
||||
const { room: roomState, roomUser } = this.state;
|
||||
const { room, roomUser } = this.state;
|
||||
|
||||
if (_.isEmpty(roomUser)) {
|
||||
try {
|
||||
const roomUserId = RocketChat.getUidDirectMessage(roomState);
|
||||
const roomUserId = RocketChat.getUidDirectMessage(room);
|
||||
const result = await RocketChat.getUserInfo(roomUserId);
|
||||
if (result.success) {
|
||||
const { user } = result;
|
||||
|
@ -183,9 +186,7 @@ class RoomInfoView extends React.Component {
|
|||
}));
|
||||
}
|
||||
|
||||
const room = await this.getDirect(user.username);
|
||||
|
||||
this.setState({ roomUser: user, room: { ...roomState, rid: room.rid } });
|
||||
this.setState({ roomUser: user });
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
|
@ -220,16 +221,28 @@ class RoomInfoView extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
getDirect = async(username) => {
|
||||
createDirect = () => new Promise(async(resolve, reject) => {
|
||||
const { route } = this.props;
|
||||
|
||||
// We don't need to create a direct
|
||||
const member = route.params?.member;
|
||||
if (!_.isEmpty(member)) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
// TODO: Check if some direct with the user already exists on database
|
||||
try {
|
||||
const { roomUser: { username } } = this.state;
|
||||
const result = await RocketChat.createDirectMessage(username);
|
||||
if (result.success) {
|
||||
return result.room;
|
||||
const { room: { rid } } = result;
|
||||
return this.setState(({ room }) => ({ room: { ...room, rid } }), resolve);
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
reject();
|
||||
})
|
||||
|
||||
goRoom = () => {
|
||||
const { roomUser, room } = this.state;
|
||||
|
@ -287,9 +300,19 @@ class RoomInfoView extends React.Component {
|
|||
|
||||
renderButton = (onPress, iconName, text) => {
|
||||
const { theme } = this.props;
|
||||
|
||||
const onActionPress = async() => {
|
||||
try {
|
||||
await this.createDirect();
|
||||
onPress();
|
||||
} catch {
|
||||
EventEmitter.emit(LISTENER, { message: I18n.t('error-action-not-allowed', { action: I18n.t('Create_Direct_Messages') }) });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<BorderlessButton
|
||||
onPress={onPress}
|
||||
onPress={onActionPress}
|
||||
style={styles.roomButton}
|
||||
>
|
||||
<CustomIcon
|
||||
|
@ -302,12 +325,15 @@ class RoomInfoView extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
renderButtons = () => (
|
||||
renderButtons = () => {
|
||||
const { jitsiEnabled } = this.props;
|
||||
return (
|
||||
<View style={styles.roomButtonsContainer}>
|
||||
{this.renderButton(this.goRoom, 'message', I18n.t('Message'))}
|
||||
{this.renderButton(this.videoCall, 'video-1', I18n.t('Video_call'))}
|
||||
{jitsiEnabled ? this.renderButton(this.videoCall, 'video-1', I18n.t('Video_call')) : null}
|
||||
</View>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
const { room, roomUser } = this.state;
|
||||
|
@ -348,7 +374,8 @@ const mapStateToProps = state => ({
|
|||
baseUrl: state.server.server,
|
||||
user: getUserSelector(state),
|
||||
rooms: state.room.rooms,
|
||||
isMasterDetail: state.app.isMasterDetail
|
||||
isMasterDetail: state.app.isMasterDetail,
|
||||
jitsiEnabled: state.settings.Jitsi_Enabled || false
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(withTheme(RoomInfoView));
|
||||
|
|
Loading…
Reference in New Issue