Chore: Migrate REST API - getCommandPreview and executeCommandPreview to Typescript (#3897)

This commit is contained in:
Reinaldo Neto 2022-03-15 11:41:23 -03:00 committed by GitHub
parent 8a1f81d707
commit 2cc4b9c1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 13 deletions

View File

@ -6,9 +6,10 @@ import Item from './Item';
import styles from '../styles'; import styles from '../styles';
import { themes } from '../../../constants/colors'; import { themes } from '../../../constants/colors';
import { withTheme } from '../../../theme'; import { withTheme } from '../../../theme';
import { IPreviewItem } from '../../../definitions';
interface IMessageBoxCommandsPreview { interface IMessageBoxCommandsPreview {
commandPreview: []; commandPreview: IPreviewItem[];
showCommandPreview: boolean; showCommandPreview: boolean;
theme?: string; theme?: string;
} }

View File

@ -49,7 +49,7 @@ 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 { IUser } from '../../definitions'; import { IPreviewItem, IUser } from '../../definitions';
if (isAndroid) { if (isAndroid) {
require('./EmojiKeyboard'); require('./EmojiKeyboard');
@ -114,7 +114,7 @@ interface IMessageBoxState {
showSend: any; showSend: any;
recording: boolean; recording: boolean;
trackingType: string; trackingType: string;
commandPreview: []; commandPreview: IPreviewItem[];
showCommandPreview: boolean; showCommandPreview: boolean;
command: { command: {
appId?: any; appId?: any;
@ -643,7 +643,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
try { try {
const response = await RocketChat.getCommandPreview(name, rid, params); const response = await RocketChat.getCommandPreview(name, rid, params);
if (response.success) { 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) { } catch (e) {
log(e); log(e);

View File

@ -14,3 +14,10 @@ export interface ISlashCommandResult extends ISlashCommand {
} }
export type TSlashCommandModel = ISlashCommand & Model; 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;
}

View File

@ -1,10 +1,20 @@
import { IPreviewItem } from '../../ISlashCommand';
export type CommandsEndpoints = { export type CommandsEndpoints = {
'commands.preview': { 'commands.preview': {
GET: (params: { command: string; roomId: string; params: string }) => { GET: (params: { command: string; params: string; roomId: string }) => {
preview: { preview?: {
i18nTitle: string; i18nTitle: string;
items: any; items: IPreviewItem[];
}; };
}; };
POST: (params: {
command: string;
params: string;
roomId: string;
previewItem: IPreviewItem;
triggerId: string;
tmid?: string;
}) => {};
}; };
}; };

View File

@ -7,7 +7,8 @@ import {
IRoomNotifications, IRoomNotifications,
TRocketChat, TRocketChat,
IMessage, IMessage,
IRoom IRoom,
IPreviewItem
} from '../../../definitions'; } from '../../../definitions';
import { ISpotlight } from '../../../definitions/ISpotlight'; import { ISpotlight } from '../../../definitions/ISpotlight';
import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces'; import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces';
@ -696,15 +697,13 @@ export const getCommandPreview = (command: string, roomId: string, params: strin
export const executeCommandPreview = ( export const executeCommandPreview = (
command: string, command: string,
params: any, params: string,
roomId: string, roomId: string,
previewItem: any, previewItem: IPreviewItem,
triggerId: string, triggerId: string,
tmid?: string tmid?: string
): any => ) =>
// RC 0.65.0 // RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('commands.preview', { sdk.post('commands.preview', {
command, command,
params, params,