[CHORE] Refactor RoomActionsView permissions (#2872)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gung Wah 2021-03-19 01:33:20 +08:00 committed by GitHub
parent 715cc1eab7
commit 83b7f3867d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -125,18 +125,22 @@ class RoomActionsView extends React.Component {
this.updateRoomMember(); this.updateRoomMember();
} }
const canAutoTranslate = RocketChat.canAutoTranslate(); const canAutoTranslate = await RocketChat.canAutoTranslate();
this.setState({ canAutoTranslate }); const canAddUser = await this.canAddUser();
const canInviteUser = await this.canInviteUser();
const canEdit = await this.canEdit();
const canToggleEncryption = await this.canToggleEncryption();
const canViewMembers = await this.canViewMembers();
this.canAddUser(); this.setState({
this.canInviteUser(); canAutoTranslate, canAddUser, canInviteUser, canEdit, canToggleEncryption, canViewMembers
this.canEdit(); });
this.canToggleEncryption();
// livechat permissions // livechat permissions
if (room.t === 'l') { if (room.t === 'l') {
this.canForwardGuest(); const canForwardGuest = await this.canForwardGuest();
this.canReturnQueue(); const canReturnQueue = await this.canReturnQueue();
this.setState({ canForwardGuest, canReturnQueue });
} }
} }
} }
@ -182,7 +186,7 @@ class RoomActionsView extends React.Component {
if (t === 'p' && permissions[2]) { if (t === 'p' && permissions[2]) {
canAddUser = true; canAddUser = true;
} }
this.setState({ canAddUser }); return canAddUser;
} }
canInviteUser = async() => { canInviteUser = async() => {
@ -192,7 +196,7 @@ class RoomActionsView extends React.Component {
const permissions = await RocketChat.hasPermission([createInviteLinksPermission], rid); const permissions = await RocketChat.hasPermission([createInviteLinksPermission], rid);
const canInviteUser = permissions[0]; const canInviteUser = permissions[0];
this.setState({ canInviteUser }); return canInviteUser;
} }
canEdit = async() => { canEdit = async() => {
@ -202,7 +206,7 @@ class RoomActionsView extends React.Component {
const permissions = await RocketChat.hasPermission([editRoomPermission], rid); const permissions = await RocketChat.hasPermission([editRoomPermission], rid);
const canEdit = permissions[0]; const canEdit = permissions[0];
this.setState({ canEdit }); return canEdit;
} }
canToggleEncryption = async() => { canToggleEncryption = async() => {
@ -212,7 +216,7 @@ class RoomActionsView extends React.Component {
const permissions = await RocketChat.hasPermission([toggleRoomE2EEncryptionPermission], rid); const permissions = await RocketChat.hasPermission([toggleRoomE2EEncryptionPermission], rid);
const canToggleEncryption = permissions[0]; const canToggleEncryption = permissions[0];
this.setState({ canToggleEncryption }); return canToggleEncryption;
} }
canViewMembers = async() => { canViewMembers = async() => {
@ -229,7 +233,6 @@ class RoomActionsView extends React.Component {
// This method is executed only in componentDidMount and returns a value // This method is executed only in componentDidMount and returns a value
// We save the state to read in render // We save the state to read in render
const result = (t === 'c' || t === 'p'); const result = (t === 'c' || t === 'p');
this.setState({ canViewMembers: result });
return result; return result;
} }
@ -238,13 +241,13 @@ class RoomActionsView extends React.Component {
const { transferLivechatGuestPermission } = this.props; const { transferLivechatGuestPermission } = this.props;
const { rid } = room; const { rid } = room;
const permissions = await RocketChat.hasPermission([transferLivechatGuestPermission], rid); const permissions = await RocketChat.hasPermission([transferLivechatGuestPermission], rid);
this.setState({ canForwardGuest: permissions[0] }); return permissions[0];
} }
canReturnQueue = async() => { canReturnQueue = async() => {
try { try {
const { returnQueue } = await RocketChat.getRoutingConfig(); const { returnQueue } = await RocketChat.getRoutingConfig();
this.setState({ canReturnQueue: returnQueue }); return returnQueue;
} catch { } catch {
// do nothing // do nothing
} }
@ -582,6 +585,7 @@ class RoomActionsView extends React.Component {
rid, t, encrypted rid, t, encrypted
} = room; } = room;
const isGroupChat = RocketChat.isGroupChat(room); const isGroupChat = RocketChat.isGroupChat(room);
return ( return (
<SafeAreaView testID='room-actions-view'> <SafeAreaView testID='room-actions-view'>
<StatusBar /> <StatusBar />