diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 82ef2760c..c75ccaddb 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -314,7 +314,8 @@ class MessageBox extends Component { tshow, mentionLoading, trackingType, - permissionToUpload + permissionToUpload, + canViewCannedResponse } = this.state; const { roomType, replying, editing, isFocused, message, theme, usedCannedResponse, uploadFilePermission } = this.props; @@ -373,8 +374,11 @@ class MessageBox extends Component { } componentDidUpdate(prevProps: IMessageBoxProps) { - const { uploadFilePermission } = this.props; - if (!dequal(prevProps.uploadFilePermission, uploadFilePermission)) { + const { uploadFilePermission, viewCannedResponsesPermission } = this.props; + if ( + !dequal(prevProps.uploadFilePermission, uploadFilePermission) || + prevProps.viewCannedResponsesPermission !== viewCannedResponsesPermission + ) { this.setOptions(); } } @@ -412,12 +416,12 @@ class MessageBox extends Component { canViewCannedResponse = async () => { const { viewCannedResponsesPermission, rid } = this.props; - const permissions = await RocketChat.hasPermission([viewCannedResponsesPermission], rid); + const permissions = await hasPermission([viewCannedResponsesPermission], rid); return permissions[0]; }; setOptions = async () => { - const { uploadFilePermission, rid } = this.props; + const { uploadFilePermission, viewCannedResponsesPermission, rid } = this.props; // Servers older than 4.2 if (!uploadFilePermission) { @@ -425,8 +429,8 @@ class MessageBox extends Component { return; } - const permissionToUpload = await hasPermission([uploadFilePermission], rid); - this.setState({ permissionToUpload: permissionToUpload[0] }); + const permissions = await hasPermission([uploadFilePermission, viewCannedResponsesPermission], rid); + this.setState({ permissionToUpload: permissions[0], canViewCannedResponse: permissions[1] }); }; onChangeText: any = (text: string): void => { @@ -795,11 +799,11 @@ class MessageBox extends Component { showMessageBoxActions = () => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); - const { permissionToUpload, canViewCannedResponse } = this.state; - const { showActionSheet, goToCannedResponses } = this.props; + const { permissionToUpload } = this.state; + const { showActionSheet, goToCannedResponses, roomType } = this.props; const options = []; - if (canViewCannedResponse) { + if (roomType === 'l' && goToCannedResponses) { options.push({ title: I18n.t('Canned_Responses'), icon: 'canned-response', diff --git a/app/views/RoomActionsView/index.tsx b/app/views/RoomActionsView/index.tsx index 4a92f7469..2d1a4212e 100644 --- a/app/views/RoomActionsView/index.tsx +++ b/app/views/RoomActionsView/index.tsx @@ -69,7 +69,6 @@ interface IRoomActionsViewProps extends IBaseScreen { - const { livechatAllowManualOnHold } = this.props; - const { room } = this.state; - - return !!(livechatAllowManualOnHold && !room?.lastMessage?.token && room?.lastMessage?.u && !room.onHold); - }; - renderEncryptedSwitch = () => { const { room, canToggleEncryption, canEdit } = this.state; const { encrypted } = room; @@ -1034,7 +1026,7 @@ class RoomActionsView extends React.Component } + left={() => } showActionIndicator /> diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 6d1c2e18a..d5f84488f 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -344,7 +344,7 @@ class RoomView extends React.Component { shouldComponentUpdate(nextProps: IRoomViewProps, nextState: IRoomViewState) { const { state } = this; - const { roomUpdate, member } = state; + const { roomUpdate, member, isOnHold } = state; const { appState, theme, insets, route } = this.props; if (theme !== nextProps.theme) { return true; @@ -355,7 +355,9 @@ class RoomView extends React.Component { if (member.statusText !== nextState.member.statusText) { return true; } - + if (isOnHold !== nextState.isOnHold) { + return true; + } const stateUpdated = stateAttrsUpdate.some(key => nextState[key] !== state[key]); if (stateUpdated) { return true; @@ -370,8 +372,8 @@ class RoomView extends React.Component { } componentDidUpdate(prevProps: IRoomViewProps, prevState: IRoomViewState) { - const { roomUpdate, joined, isOnHold } = this.state; - const { appState, insets, route, livechatAllowManualOnHold } = this.props; + const { roomUpdate, joined, room } = this.state; + const { appState, insets, route } = this.props; if (route?.params?.jumpToMessageId && route?.params?.jumpToMessageId !== prevProps.route?.params?.jumpToMessageId) { this.jumpToMessage(route?.params?.jumpToMessageId); @@ -396,16 +398,14 @@ class RoomView extends React.Component { // If it's a livechat room if (this.t === 'l') { if ( + !room.lastMessage?.token || !dequal(prevState.roomUpdate.visitor, roomUpdate.visitor) || !dequal(prevState.roomUpdate.status, roomUpdate.status) || prevState.joined !== joined ) { - this.setHeader(); - } - - if (isOnHold !== prevState.isOnHold || prevProps.livechatAllowManualOnHold !== livechatAllowManualOnHold) { const canPlaceLivechatOnHold = this.canPlaceLivechatOnHold(); this.setState({ canPlaceLivechatOnHold }); + this.setHeader(); } } if (roomUpdate.teamMain !== prevState.roomUpdate.teamMain || roomUpdate.teamId !== prevState.roomUpdate.teamId) { @@ -489,7 +489,6 @@ class RoomView extends React.Component { canPlaceLivechatOnHold = () => { const { livechatAllowManualOnHold } = this.props; const { room } = this.state; - return !!(livechatAllowManualOnHold && !room?.lastMessage?.token && room?.lastMessage?.u && !room.onHold); }; @@ -1278,7 +1277,7 @@ class RoomView extends React.Component { dateSeparator = item.ts; } } - + console.log({ item }); let content = null; if (item.t && MESSAGE_TYPE_ANY_LOAD.includes(item.t as MessageTypeLoad)) { content = ( @@ -1346,7 +1345,8 @@ class RoomView extends React.Component { }; renderFooter = () => { - const { joined, room, selectedMessage, editing, replying, replyWithMention, readOnly, loading } = this.state; + const { joined, room, selectedMessage, editing, replying, replyWithMention, readOnly, loading, canViewCannedResponse } = + this.state; const { navigation, theme, route } = this.props; const usedCannedResponse = route?.params?.usedCannedResponse; @@ -1413,7 +1413,7 @@ class RoomView extends React.Component { return (