diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 00459320b..aea1a9717 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -50,9 +50,10 @@ import { sanitizeLikeString } from '../../lib/database/utils'; import { CustomIcon } from '../../lib/Icons'; import { IMessage } from '../../definitions/IMessage'; import { forceJpgExtension } from './forceJpgExtension'; -import { IBaseScreen, IPreviewItem, IUser, TSubscriptionModel, TThreadModel } from '../../definitions'; +import { IApplicationState, IBaseScreen, IPreviewItem, IUser, TSubscriptionModel, TThreadModel } from '../../definitions'; import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types'; import { TSupportedThemes } from '../../theme'; +import { ChatsStackParamList } from '../../stacks/types'; if (isAndroid) { require('./EmojiKeyboard'); @@ -76,7 +77,7 @@ const videoPickerConfig: Options = { mediaType: 'video' }; -export interface IMessageBoxProps extends IBaseScreen { +export interface IMessageBoxProps extends IBaseScreen { rid: string; baseUrl: string; message: IMessage; @@ -108,6 +109,8 @@ export interface IMessageBoxProps extends IBaseScreen void; } interface IMessageBoxState { @@ -124,6 +127,7 @@ interface IMessageBoxState { tshow: boolean; mentionLoading: boolean; permissionToUpload: boolean; + canViewCannedResponse: boolean; } class MessageBox extends Component { @@ -178,7 +182,8 @@ class MessageBox extends Component { command: {}, tshow: false, mentionLoading: false, - permissionToUpload: true + permissionToUpload: true, + canViewCannedResponse: false }; this.text = ''; this.selection = { start: 0, end: 0 }; @@ -208,7 +213,7 @@ class MessageBox extends Component { async componentDidMount() { const db = database.active; - const { rid, tmid, navigation, sharing, usedCannedResponse, isMasterDetail } = this.props; + const { rid, tmid, navigation, sharing, usedCannedResponse, isMasterDetail, roomType } = this.props; let msg; try { const threadsCollection = db.get('threads'); @@ -247,6 +252,11 @@ class MessageBox extends Component { this.onChangeText(usedCannedResponse); } + if (roomType === 'l') { + const canViewCannedResponse = await this.canViewCannedResponse(); + this.setState({ canViewCannedResponse }); + } + this.setOptions(); this.unsubscribeFocus = navigation.addListener('focus', () => { @@ -399,6 +409,12 @@ class MessageBox extends Component { } } + canViewCannedResponse = async () => { + const { viewCannedResponsesPermission, rid } = this.props; + const permissions = await RocketChat.hasPermission([viewCannedResponsesPermission], rid); + return permissions[0]; + }; + setOptions = async () => { const { uploadFilePermission, rid } = this.props; @@ -778,10 +794,17 @@ class MessageBox extends Component { showMessageBoxActions = () => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); - const { permissionToUpload } = this.state; - const { showActionSheet } = this.props; + const { permissionToUpload, canViewCannedResponse } = this.state; + const { showActionSheet, goToCannedResponses } = this.props; const options = []; + if (canViewCannedResponse) { + options.push({ + title: I18n.t('Canned_Responses'), + icon: 'canned-response', + onPress: () => goToCannedResponses() + }); + } if (permissionToUpload) { options.push( { @@ -1166,7 +1189,7 @@ class MessageBox extends Component { } } -const mapStateToProps = (state: any) => ({ +const mapStateToProps = (state: IApplicationState) => ({ isMasterDetail: state.app.isMasterDetail, baseUrl: state.server.server, threadsEnabled: state.settings.Threads_enabled, @@ -1174,7 +1197,8 @@ const mapStateToProps = (state: any) => ({ FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize, Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled, - uploadFilePermission: state.permissions['mobile-upload-file'] + uploadFilePermission: state.permissions['mobile-upload-file'], + viewCannedResponsesPermission: state.permissions['view-canned-responses'] }); const dispatchToProps = { diff --git a/app/views/RoomActionsView/index.tsx b/app/views/RoomActionsView/index.tsx index 9a0b8ba89..e3ab5c437 100644 --- a/app/views/RoomActionsView/index.tsx +++ b/app/views/RoomActionsView/index.tsx @@ -976,7 +976,7 @@ class RoomActionsView extends React.Component