diff --git a/app/views/SearchMessagesView/index.tsx b/app/views/SearchMessagesView/index.tsx index 015013abc..0609e641f 100644 --- a/app/views/SearchMessagesView/index.tsx +++ b/app/views/SearchMessagesView/index.tsx @@ -6,7 +6,7 @@ import { Q } from '@nozbe/watermelondb'; import { connect } from 'react-redux'; import { dequal } from 'dequal'; -import { ISubscription, SubscriptionType } from '../../definitions/ISubscription'; +import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription'; import { IAttachment } from '../../definitions/IAttachment'; import FormTextInput from '../../containers/TextInput/FormTextInput'; import ActivityIndicator from '../../containers/ActivityIndicator'; @@ -14,7 +14,6 @@ import Markdown from '../../containers/markdown'; import debounce from '../../utils/debounce'; import Message from '../../containers/message'; import scrollPersistTaps from '../../utils/scrollPersistTaps'; -import { IMessage } from '../../containers/message/interfaces'; import I18n from '../../i18n'; import StatusBar from '../../containers/StatusBar'; import log from '../../utils/log'; @@ -32,14 +31,14 @@ import styles from './styles'; import { InsideStackParamList, ChatsStackParamList } from '../../stacks/types'; import { IEmoji } from '../../definitions/IEmoji'; import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion'; -import { IUrl } from '../../definitions'; +import { IMessageFromServer, IUser, TMessageModel, IUrl } from '../../definitions'; import { Services } from '../../lib/services'; const QUERY_SIZE = 50; interface ISearchMessagesViewState { loading: boolean; - messages: IMessage[]; + messages: (IMessageFromServer | TMessageModel)[]; searchText: string; } @@ -60,11 +59,7 @@ interface INavigationOption { } interface ISearchMessagesViewProps extends INavigationOption { - user: { - id: string; - username: string; - token: string; - }; + user: IUser; baseUrl: string; serverVersion: string; customEmojis: { @@ -78,7 +73,7 @@ class SearchMessagesView extends React.Component { + searchMessages = async (searchText: string): Promise<(IMessageFromServer | TMessageModel)[]> => { if (!searchText) { return []; } @@ -180,7 +175,6 @@ class SearchMessagesView extends React.Component { try { const messages = await this.searchMessages(searchText); - // @ts-ignore TODO: find a way to deal with the difference between IMessageFromServer and TMessageModel expected by state this.setState(prevState => ({ messages: debounced ? messages : [...prevState.messages, ...messages], loading: false @@ -223,21 +217,28 @@ class SearchMessagesView extends React.Component { + jumpToMessage = async ({ item }: { item: IMessageFromServer | TMessageModel }) => { const { navigation } = this.props; - let params: any = { + let params: { + rid: string; + jumpToMessageId: string; + t: SubscriptionType; + room: TSubscriptionModel | undefined; + tmid?: string; + name?: string; + } = { rid: this.rid, jumpToMessageId: item._id, t: this.t, - room: this.room + room: this.room as TSubscriptionModel }; - if (item.tmid) { + if ('tmid' in item && item.tmid) { navigation.pop(); params = { ...params, tmid: item.tmid, - name: await getThreadName(this.rid, item.tmid, item._id), - t: 'thread' + name: await getThreadName(this.rid, item.tmid as string, item._id), + t: SubscriptionType.THREAD }; navigation.push('RoomView', params); } else { @@ -271,16 +272,15 @@ class SearchMessagesView extends React.Component { + renderItem = ({ item }: { item: IMessageFromServer | TMessageModel }) => { + const message = item as TMessageModel; const { user, baseUrl, theme, useRealName } = this.props; return ( this.jumpToMessage({ item })} jumpToMessage={() => this.jumpToMessage({ item })} + rid={message.rid} /> ); };