From 6ff2fc37d0e6ebb38dca015cf95c361ba0d9920f Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 14 Mar 2022 11:18:53 -0300 Subject: [PATCH] Chore: Migrate REST API - editMessage to Typescript (#3887) * Chore: Migrate REST API - editMessage to Typescript * minor tweak --- app/definitions/rest/v1/chat.ts | 5 +++++ app/lib/rocketchat/rocketchat.js | 7 ------- app/lib/rocketchat/services/restApi.ts | 9 ++++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/definitions/rest/v1/chat.ts b/app/definitions/rest/v1/chat.ts index b326e99e0..7b9deb43e 100644 --- a/app/definitions/rest/v1/chat.ts +++ b/app/definitions/rest/v1/chat.ts @@ -65,6 +65,11 @@ export type ChatEndpoints = { messages: IMessageFromServer[]; }; }; + 'chat.update': { + POST: (params: { roomId: IServerRoom['_id']; msgId: string; text: string }) => { + messages: IMessageFromServer; + }; + }; 'chat.getMessageReadReceipts': { GET: (params: { messageId: string }) => { receipts: IReadReceipts[] }; }; diff --git a/app/lib/rocketchat/rocketchat.js b/app/lib/rocketchat/rocketchat.js index 6396d5e8a..16527a0b9 100644 --- a/app/lib/rocketchat/rocketchat.js +++ b/app/lib/rocketchat/rocketchat.js @@ -11,8 +11,6 @@ import { getBundleId, isIOS } from '../../utils/deviceInfo'; import log from '../../utils/log'; import SSLPinning from '../../utils/sslPinning'; import database from '../database'; -import { sanitizeLikeString } from '../database/utils'; -import { Encryption } from '../encryption'; import triggerBlockAction, { triggerCancel, triggerSubmitView } from '../methods/actions'; import callJitsi, { callJitsiWithoutServer } from '../methods/callJitsi'; import canOpenRoom from '../methods/canOpenRoom'; @@ -298,11 +296,6 @@ const RocketChat = { return setting; }); }, - async editMessage(message) { - const { rid, msg } = await Encryption.encryptMessage(message); - // RC 0.49.0 - return this.post('chat.update', { roomId: rid, msgId: message.id, text: msg }); - }, getRoom, getPermalinkMessage, getPermalinkChannel(channel) { diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 76bf03a72..6474eda16 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -1,9 +1,10 @@ import sdk from './sdk'; import { TEAM_TYPE } from '../../../definitions/ITeam'; import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType'; -import { SubscriptionType, INotificationPreferences, IRoomNotifications } from '../../../definitions'; +import { SubscriptionType, INotificationPreferences, IRoomNotifications, IMessage } from '../../../definitions'; import { ISpotlight } from '../../../definitions/ISpotlight'; import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces'; +import { Encryption } from '../../encryption'; import { TParams } from '../../../definitions/ILivechatEditView'; export const createChannel = ({ @@ -742,3 +743,9 @@ export const useInviteToken = (token: string): any => // TODO: missing definitions from server // @ts-ignore sdk.post('useInviteToken', { token }); + +export const editMessage = async (message: IMessage) => { + const { rid, msg } = await Encryption.encryptMessage(message); + // RC 0.49.0 + return sdk.post('chat.update', { roomId: rid, msgId: message.id, text: msg }); +};