From b2bd71e83e4010c5a484b16296cff87e24289ffa Mon Sep 17 00:00:00 2001 From: Alex Junior Date: Tue, 8 Mar 2022 14:09:45 -0300 Subject: [PATCH] Chore: Server API types - chat.getDiscussions (#3776) * chore: implementing type for test api - getDiscussions * Fix DiscussionDetails count usage * chore: update getDiscussions to use IMessageFromServer Co-authored-by: Diego Mello --- app/definitions/IMessage.ts | 4 ++++ app/definitions/rest/v1/chat.ts | 4 ++-- app/views/DiscussionsView/DiscussionDetails.tsx | 4 ++-- app/views/DiscussionsView/Item.tsx | 4 ++-- app/views/DiscussionsView/index.tsx | 10 +++++----- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 7085d121..d836400f 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -83,6 +83,10 @@ export interface IMessageFromServer { files?: IMessageFile[]; groupable?: boolean; attachments?: IAttachment[]; + t?: MessageType; + drid?: string; + dcount?: number; + dml: string | Date; } export interface ILoadMoreMessage { diff --git a/app/definitions/rest/v1/chat.ts b/app/definitions/rest/v1/chat.ts index 8481f78d..417d54a2 100644 --- a/app/definitions/rest/v1/chat.ts +++ b/app/definitions/rest/v1/chat.ts @@ -1,4 +1,4 @@ -import type { IMessage } from '../../IMessage'; +import type { IMessage, IMessageFromServer } from '../../IMessage'; import type { IServerRoom } from '../../IRoom'; import { PaginatedResult } from '../helpers/PaginatedResult'; @@ -31,7 +31,7 @@ export type ChatEndpoints = { }; 'chat.getDiscussions': { GET: (params: { roomId: IServerRoom['_id']; text?: string; offset: number; count: number }) => { - messages: IMessage[]; + messages: IMessageFromServer[]; total: number; }; }; diff --git a/app/views/DiscussionsView/DiscussionDetails.tsx b/app/views/DiscussionsView/DiscussionDetails.tsx index 06d245c8..9ef19bbe 100644 --- a/app/views/DiscussionsView/DiscussionDetails.tsx +++ b/app/views/DiscussionsView/DiscussionDetails.tsx @@ -1,11 +1,11 @@ import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; -import { TThreadModel } from '../../definitions/IThread'; import { CustomIcon } from '../../lib/Icons'; import { themes } from '../../constants/colors'; import sharedStyles from '../Styles'; import { useTheme } from '../../theme'; +import { IMessageFromServer } from '../../definitions'; const styles = StyleSheet.create({ container: { @@ -31,7 +31,7 @@ const styles = StyleSheet.create({ }); interface IDiscussionDetails { - item: TThreadModel; + item: IMessageFromServer; date: string; } diff --git a/app/views/DiscussionsView/Item.tsx b/app/views/DiscussionsView/Item.tsx index 171f613b..2fa90d18 100644 --- a/app/views/DiscussionsView/Item.tsx +++ b/app/views/DiscussionsView/Item.tsx @@ -10,7 +10,7 @@ import { themes } from '../../constants/colors'; import { MarkdownPreview } from '../../containers/markdown'; import { formatDateThreads, makeThreadName } from '../../utils/room'; import DiscussionDetails from './DiscussionDetails'; -import { TThreadModel } from '../../definitions/IThread'; +import { IMessageFromServer } from '../../definitions'; const styles = StyleSheet.create({ container: { @@ -48,7 +48,7 @@ const styles = StyleSheet.create({ }); interface IItem { - item: TThreadModel; + item: IMessageFromServer; onPress: { (...args: any[]): void; stop(): void; diff --git a/app/views/DiscussionsView/index.tsx b/app/views/DiscussionsView/index.tsx index 01570100..8a977a36 100644 --- a/app/views/DiscussionsView/index.tsx +++ b/app/views/DiscussionsView/index.tsx @@ -5,7 +5,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack'; import { RouteProp } from '@react-navigation/core'; -import { IApplicationState } from '../../definitions'; +import { IApplicationState, IMessageFromServer } from '../../definitions'; import { ChatsStackParamList } from '../../stacks/types'; import ActivityIndicator from '../../containers/ActivityIndicator'; import I18n from '../../i18n'; @@ -47,8 +47,8 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem const isMasterDetail = useSelector((state: IApplicationState) => state.app?.isMasterDetail); const [loading, setLoading] = useState(false); - const [discussions, setDiscussions] = useState([]); - const [search, setSearch] = useState([]); + const [discussions, setDiscussions] = useState([]); + const [search, setSearch] = useState([]); const [isSearching, setIsSearching] = useState(false); const [total, setTotal] = useState(0); const [searchTotal, setSearchTotal] = useState(0); @@ -63,7 +63,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem setLoading(true); try { - const result: any = await RocketChat.getDiscussions({ + const result = await RocketChat.getDiscussions({ roomId: rid, offset: isSearching ? search.length : discussions.length, count: API_FETCH_COUNT, @@ -171,7 +171,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem true ); - const renderItem = ({ item }: { item: TThreadModel }) => ( + const renderItem = ({ item }: { item: IMessageFromServer }) => (