chore: add canned responses to MessageBox
This commit is contained in:
parent
1ec2f4b464
commit
a2965a3f93
|
@ -50,9 +50,10 @@ import { sanitizeLikeString } from '../../lib/database/utils';
|
||||||
import { CustomIcon } from '../../lib/Icons';
|
import { CustomIcon } from '../../lib/Icons';
|
||||||
import { IMessage } from '../../definitions/IMessage';
|
import { IMessage } from '../../definitions/IMessage';
|
||||||
import { forceJpgExtension } from './forceJpgExtension';
|
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 { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
|
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
require('./EmojiKeyboard');
|
require('./EmojiKeyboard');
|
||||||
|
@ -76,7 +77,7 @@ const videoPickerConfig: Options = {
|
||||||
mediaType: 'video'
|
mediaType: 'video'
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IMessageBoxProps extends IBaseScreen<MasterDetailInsideStackParamList, any> {
|
export interface IMessageBoxProps extends IBaseScreen<ChatsStackParamList & MasterDetailInsideStackParamList, any> {
|
||||||
rid: string;
|
rid: string;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
message: IMessage;
|
message: IMessage;
|
||||||
|
@ -108,6 +109,8 @@ export interface IMessageBoxProps extends IBaseScreen<MasterDetailInsideStackPar
|
||||||
usedCannedResponse: string;
|
usedCannedResponse: string;
|
||||||
uploadFilePermission: string[];
|
uploadFilePermission: string[];
|
||||||
serverVersion: string;
|
serverVersion: string;
|
||||||
|
viewCannedResponsesPermission: boolean;
|
||||||
|
goToCannedResponses: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IMessageBoxState {
|
interface IMessageBoxState {
|
||||||
|
@ -124,6 +127,7 @@ interface IMessageBoxState {
|
||||||
tshow: boolean;
|
tshow: boolean;
|
||||||
mentionLoading: boolean;
|
mentionLoading: boolean;
|
||||||
permissionToUpload: boolean;
|
permissionToUpload: boolean;
|
||||||
|
canViewCannedResponse: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
|
@ -178,7 +182,8 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
command: {},
|
command: {},
|
||||||
tshow: false,
|
tshow: false,
|
||||||
mentionLoading: false,
|
mentionLoading: false,
|
||||||
permissionToUpload: true
|
permissionToUpload: true,
|
||||||
|
canViewCannedResponse: false
|
||||||
};
|
};
|
||||||
this.text = '';
|
this.text = '';
|
||||||
this.selection = { start: 0, end: 0 };
|
this.selection = { start: 0, end: 0 };
|
||||||
|
@ -208,7 +213,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const db = database.active;
|
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;
|
let msg;
|
||||||
try {
|
try {
|
||||||
const threadsCollection = db.get('threads');
|
const threadsCollection = db.get('threads');
|
||||||
|
@ -247,6 +252,11 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
this.onChangeText(usedCannedResponse);
|
this.onChangeText(usedCannedResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (roomType === 'l') {
|
||||||
|
const canViewCannedResponse = await this.canViewCannedResponse();
|
||||||
|
this.setState({ canViewCannedResponse });
|
||||||
|
}
|
||||||
|
|
||||||
this.setOptions();
|
this.setOptions();
|
||||||
|
|
||||||
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
||||||
|
@ -399,6 +409,12 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canViewCannedResponse = async () => {
|
||||||
|
const { viewCannedResponsesPermission, rid } = this.props;
|
||||||
|
const permissions = await RocketChat.hasPermission([viewCannedResponsesPermission], rid);
|
||||||
|
return permissions[0];
|
||||||
|
};
|
||||||
|
|
||||||
setOptions = async () => {
|
setOptions = async () => {
|
||||||
const { uploadFilePermission, rid } = this.props;
|
const { uploadFilePermission, rid } = this.props;
|
||||||
|
|
||||||
|
@ -778,10 +794,17 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
|
|
||||||
showMessageBoxActions = () => {
|
showMessageBoxActions = () => {
|
||||||
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
logEvent(events.ROOM_SHOW_BOX_ACTIONS);
|
||||||
const { permissionToUpload } = this.state;
|
const { permissionToUpload, canViewCannedResponse } = this.state;
|
||||||
const { showActionSheet } = this.props;
|
const { showActionSheet, goToCannedResponses } = this.props;
|
||||||
|
|
||||||
const options = [];
|
const options = [];
|
||||||
|
if (canViewCannedResponse) {
|
||||||
|
options.push({
|
||||||
|
title: I18n.t('Canned_Responses'),
|
||||||
|
icon: 'canned-response',
|
||||||
|
onPress: () => goToCannedResponses()
|
||||||
|
});
|
||||||
|
}
|
||||||
if (permissionToUpload) {
|
if (permissionToUpload) {
|
||||||
options.push(
|
options.push(
|
||||||
{
|
{
|
||||||
|
@ -1166,7 +1189,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: any) => ({
|
const mapStateToProps = (state: IApplicationState) => ({
|
||||||
isMasterDetail: state.app.isMasterDetail,
|
isMasterDetail: state.app.isMasterDetail,
|
||||||
baseUrl: state.server.server,
|
baseUrl: state.server.server,
|
||||||
threadsEnabled: state.settings.Threads_enabled,
|
threadsEnabled: state.settings.Threads_enabled,
|
||||||
|
@ -1174,7 +1197,8 @@ const mapStateToProps = (state: any) => ({
|
||||||
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList,
|
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList,
|
||||||
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize,
|
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize,
|
||||||
Message_AudioRecorderEnabled: state.settings.Message_AudioRecorderEnabled,
|
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 = {
|
const dispatchToProps = {
|
||||||
|
|
|
@ -976,7 +976,7 @@ class RoomActionsView extends React.Component<IRoomActionsViewProps, IRoomAction
|
||||||
const { rid, t } = room;
|
const { rid, t } = room;
|
||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
|
||||||
if (t !== 'l' && this.isOmnichannelPreview) {
|
if (t !== 'l' || this.isOmnichannelPreview) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue