Chore: Evaluate SearchMessagesView - TypeScript (#4122)
* Chore: Evaluate SearchMessagesView - TypeScript * minor tweaks * Update app/views/SearchMessagesView/index.tsx Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com> Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
This commit is contained in:
parent
b1ffffb04b
commit
41721757d0
|
@ -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<ISearchMessagesViewProps, ISear
|
|||
|
||||
private rid: string;
|
||||
|
||||
private t: string | undefined;
|
||||
private t: SubscriptionType;
|
||||
|
||||
private encrypted: boolean | undefined;
|
||||
|
||||
|
@ -135,7 +130,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
|||
}
|
||||
|
||||
// Handle encrypted rooms search messages
|
||||
searchMessages = async (searchText: string) => {
|
||||
searchMessages = async (searchText: string): Promise<(IMessageFromServer | TMessageModel)[]> => {
|
||||
if (!searchText) {
|
||||
return [];
|
||||
}
|
||||
|
@ -180,7 +175,6 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
|||
getMessages = async (searchText: string, debounced?: boolean) => {
|
||||
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<ISearchMessagesViewProps, ISear
|
|||
navigation.navigate('RoomInfoView', navParam);
|
||||
};
|
||||
|
||||
jumpToMessage = async ({ item }: { item: IMessage }) => {
|
||||
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<ISearchMessagesViewProps, ISear
|
|||
);
|
||||
};
|
||||
|
||||
renderItem = ({ item }: { item: IMessage }) => {
|
||||
renderItem = ({ item }: { item: IMessageFromServer | TMessageModel }) => {
|
||||
const message = item as TMessageModel;
|
||||
const { user, baseUrl, theme, useRealName } = this.props;
|
||||
return (
|
||||
<Message
|
||||
// @ts-ignore IMessage | TMessageModel?
|
||||
item={item}
|
||||
item={message}
|
||||
baseUrl={baseUrl}
|
||||
user={user}
|
||||
timeFormat='MMM Do YYYY, h:mm:ss a'
|
||||
isHeader
|
||||
isThreadRoom
|
||||
showAttachment={this.showAttachment}
|
||||
getCustomEmoji={this.getCustomEmoji}
|
||||
|
@ -289,6 +289,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
|||
theme={theme}
|
||||
onPress={() => this.jumpToMessage({ item })}
|
||||
jumpToMessage={() => this.jumpToMessage({ item })}
|
||||
rid={message.rid}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue