From 7bf0de582523e7e3a302b2f0356f15d6afba2809 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 14 Mar 2022 10:32:22 -0300 Subject: [PATCH] Chore: Migrate REST API - getReadReceipts to Typescript (#3877) --- app/definitions/IMessage.ts | 10 ++++++++++ app/definitions/rest/v1/chat.ts | 5 ++++- app/lib/rocketchat/services/restApi.ts | 4 +--- app/views/ReadReceiptView/index.tsx | 18 +++--------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index aa4a293e4..25b6385d8 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -147,3 +147,13 @@ export type TMessageModel = IMessage & Model; export type TAnyMessageModel = TMessageModel | TThreadModel | TThreadMessageModel; export type TTypeMessages = IMessageFromServer | ILoadMoreMessage | IMessage; + +// Read receipts to ReadReceiptView and chat.getMessageReadReceipts +export interface IReadReceipts { + _id: string; + roomId: string; + userId: string; + messageId: string; + ts: string; + user?: IUserMessage; +} diff --git a/app/definitions/rest/v1/chat.ts b/app/definitions/rest/v1/chat.ts index 07edd43ed..b326e99e0 100644 --- a/app/definitions/rest/v1/chat.ts +++ b/app/definitions/rest/v1/chat.ts @@ -1,4 +1,4 @@ -import type { IMessage, IMessageFromServer } from '../../IMessage'; +import type { IMessage, IMessageFromServer, IReadReceipts } from '../../IMessage'; import type { IServerRoom } from '../../IRoom'; import { PaginatedResult } from '../helpers/PaginatedResult'; @@ -65,4 +65,7 @@ export type ChatEndpoints = { messages: IMessageFromServer[]; }; }; + 'chat.getMessageReadReceipts': { + GET: (params: { messageId: string }) => { receipts: IReadReceipts[] }; + }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 4d86fc14c..76bf03a72 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -617,10 +617,8 @@ export const getMessages = ( }); }; -export const getReadReceipts = (messageId: string): any => +export const getReadReceipts = (messageId: string) => // RC 0.63.0 - // TODO: missing definitions from server - // @ts-ignore sdk.get('chat.getMessageReadReceipts', { messageId }); diff --git a/app/views/ReadReceiptView/index.tsx b/app/views/ReadReceiptView/index.tsx index a40327b21..01e628302 100644 --- a/app/views/ReadReceiptView/index.tsx +++ b/app/views/ReadReceiptView/index.tsx @@ -17,23 +17,11 @@ import { themes } from '../../constants/colors'; import SafeAreaView from '../../containers/SafeAreaView'; import styles from './styles'; import { ChatsStackParamList } from '../../stacks/types'; - -interface IReceipts { - _id: string; - roomId: string; - userId: string; - messageId: string; - ts: string; - user?: { - _id: string; - name: string; - username: string; - }; -} +import { IReadReceipts } from '../../definitions'; interface IReadReceiptViewState { loading: boolean; - receipts: IReceipts[]; + receipts: IReadReceipts[]; } interface INavigationOption { @@ -125,7 +113,7 @@ class ReadReceiptView extends React.Component { + renderItem = ({ item }: { item: IReadReceipts }) => { const { theme, Message_TimeAndDateFormat } = this.props; const time = moment(item.ts).format(Message_TimeAndDateFormat); if (!item?.user?.username) {