Chore: Migrate REST API - getCommandPreview and executeCommandPreview to Typescript (#3897)
This commit is contained in:
parent
8a1f81d707
commit
2cc4b9c1ba
|
@ -6,9 +6,10 @@ import Item from './Item';
|
|||
import styles from '../styles';
|
||||
import { themes } from '../../../constants/colors';
|
||||
import { withTheme } from '../../../theme';
|
||||
import { IPreviewItem } from '../../../definitions';
|
||||
|
||||
interface IMessageBoxCommandsPreview {
|
||||
commandPreview: [];
|
||||
commandPreview: IPreviewItem[];
|
||||
showCommandPreview: boolean;
|
||||
theme?: string;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ import { sanitizeLikeString } from '../../lib/database/utils';
|
|||
import { CustomIcon } from '../../lib/Icons';
|
||||
import { IMessage } from '../../definitions/IMessage';
|
||||
import { forceJpgExtension } from './forceJpgExtension';
|
||||
import { IUser } from '../../definitions';
|
||||
import { IPreviewItem, IUser } from '../../definitions';
|
||||
|
||||
if (isAndroid) {
|
||||
require('./EmojiKeyboard');
|
||||
|
@ -114,7 +114,7 @@ interface IMessageBoxState {
|
|||
showSend: any;
|
||||
recording: boolean;
|
||||
trackingType: string;
|
||||
commandPreview: [];
|
||||
commandPreview: IPreviewItem[];
|
||||
showCommandPreview: boolean;
|
||||
command: {
|
||||
appId?: any;
|
||||
|
@ -643,7 +643,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
|
|||
try {
|
||||
const response = await RocketChat.getCommandPreview(name, rid, params);
|
||||
if (response.success) {
|
||||
return this.setState({ commandPreview: response.preview?.items, showCommandPreview: true, command });
|
||||
return this.setState({ commandPreview: response.preview?.items || [], showCommandPreview: true, command });
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
|
|
|
@ -14,3 +14,10 @@ export interface ISlashCommandResult extends ISlashCommand {
|
|||
}
|
||||
|
||||
export type TSlashCommandModel = ISlashCommand & Model;
|
||||
|
||||
// For Command Preview ex: /giphy or /tenor in open.rocket.chat
|
||||
export interface IPreviewItem {
|
||||
id: string;
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
import { IPreviewItem } from '../../ISlashCommand';
|
||||
|
||||
export type CommandsEndpoints = {
|
||||
'commands.preview': {
|
||||
GET: (params: { command: string; roomId: string; params: string }) => {
|
||||
preview: {
|
||||
GET: (params: { command: string; params: string; roomId: string }) => {
|
||||
preview?: {
|
||||
i18nTitle: string;
|
||||
items: any;
|
||||
items: IPreviewItem[];
|
||||
};
|
||||
};
|
||||
POST: (params: {
|
||||
command: string;
|
||||
params: string;
|
||||
roomId: string;
|
||||
previewItem: IPreviewItem;
|
||||
triggerId: string;
|
||||
tmid?: string;
|
||||
}) => {};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,7 +7,8 @@ import {
|
|||
IRoomNotifications,
|
||||
TRocketChat,
|
||||
IMessage,
|
||||
IRoom
|
||||
IRoom,
|
||||
IPreviewItem
|
||||
} from '../../../definitions';
|
||||
import { ISpotlight } from '../../../definitions/ISpotlight';
|
||||
import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces';
|
||||
|
@ -696,15 +697,13 @@ export const getCommandPreview = (command: string, roomId: string, params: strin
|
|||
|
||||
export const executeCommandPreview = (
|
||||
command: string,
|
||||
params: any,
|
||||
params: string,
|
||||
roomId: string,
|
||||
previewItem: any,
|
||||
previewItem: IPreviewItem,
|
||||
triggerId: string,
|
||||
tmid?: string
|
||||
): any =>
|
||||
) =>
|
||||
// RC 0.65.0
|
||||
// TODO: missing definitions from server
|
||||
// @ts-ignore
|
||||
sdk.post('commands.preview', {
|
||||
command,
|
||||
params,
|
||||
|
|
Loading…
Reference in New Issue