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 { connect } from 'react-redux';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
|
|
||||||
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
|
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscription';
|
||||||
import { IAttachment } from '../../definitions/IAttachment';
|
import { IAttachment } from '../../definitions/IAttachment';
|
||||||
import FormTextInput from '../../containers/TextInput/FormTextInput';
|
import FormTextInput from '../../containers/TextInput/FormTextInput';
|
||||||
import ActivityIndicator from '../../containers/ActivityIndicator';
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
||||||
|
@ -14,7 +14,6 @@ import Markdown from '../../containers/markdown';
|
||||||
import debounce from '../../utils/debounce';
|
import debounce from '../../utils/debounce';
|
||||||
import Message from '../../containers/message';
|
import Message from '../../containers/message';
|
||||||
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
||||||
import { IMessage } from '../../containers/message/interfaces';
|
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
import log from '../../utils/log';
|
import log from '../../utils/log';
|
||||||
|
@ -32,14 +31,14 @@ import styles from './styles';
|
||||||
import { InsideStackParamList, ChatsStackParamList } from '../../stacks/types';
|
import { InsideStackParamList, ChatsStackParamList } from '../../stacks/types';
|
||||||
import { IEmoji } from '../../definitions/IEmoji';
|
import { IEmoji } from '../../definitions/IEmoji';
|
||||||
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
|
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
|
||||||
import { IUrl } from '../../definitions';
|
import { IMessageFromServer, IUser, TMessageModel, IUrl } from '../../definitions';
|
||||||
import { Services } from '../../lib/services';
|
import { Services } from '../../lib/services';
|
||||||
|
|
||||||
const QUERY_SIZE = 50;
|
const QUERY_SIZE = 50;
|
||||||
|
|
||||||
interface ISearchMessagesViewState {
|
interface ISearchMessagesViewState {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
messages: IMessage[];
|
messages: (IMessageFromServer | TMessageModel)[];
|
||||||
searchText: string;
|
searchText: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +59,7 @@ interface INavigationOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISearchMessagesViewProps extends INavigationOption {
|
interface ISearchMessagesViewProps extends INavigationOption {
|
||||||
user: {
|
user: IUser;
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
token: string;
|
|
||||||
};
|
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
serverVersion: string;
|
serverVersion: string;
|
||||||
customEmojis: {
|
customEmojis: {
|
||||||
|
@ -78,7 +73,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
|
|
||||||
private rid: string;
|
private rid: string;
|
||||||
|
|
||||||
private t: string | undefined;
|
private t: SubscriptionType;
|
||||||
|
|
||||||
private encrypted: boolean | undefined;
|
private encrypted: boolean | undefined;
|
||||||
|
|
||||||
|
@ -135,7 +130,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle encrypted rooms search messages
|
// Handle encrypted rooms search messages
|
||||||
searchMessages = async (searchText: string) => {
|
searchMessages = async (searchText: string): Promise<(IMessageFromServer | TMessageModel)[]> => {
|
||||||
if (!searchText) {
|
if (!searchText) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -180,7 +175,6 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
getMessages = async (searchText: string, debounced?: boolean) => {
|
getMessages = async (searchText: string, debounced?: boolean) => {
|
||||||
try {
|
try {
|
||||||
const messages = await this.searchMessages(searchText);
|
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 => ({
|
this.setState(prevState => ({
|
||||||
messages: debounced ? messages : [...prevState.messages, ...messages],
|
messages: debounced ? messages : [...prevState.messages, ...messages],
|
||||||
loading: false
|
loading: false
|
||||||
|
@ -223,21 +217,28 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
navigation.navigate('RoomInfoView', navParam);
|
navigation.navigate('RoomInfoView', navParam);
|
||||||
};
|
};
|
||||||
|
|
||||||
jumpToMessage = async ({ item }: { item: IMessage }) => {
|
jumpToMessage = async ({ item }: { item: IMessageFromServer | TMessageModel }) => {
|
||||||
const { navigation } = this.props;
|
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,
|
rid: this.rid,
|
||||||
jumpToMessageId: item._id,
|
jumpToMessageId: item._id,
|
||||||
t: this.t,
|
t: this.t,
|
||||||
room: this.room
|
room: this.room as TSubscriptionModel
|
||||||
};
|
};
|
||||||
if (item.tmid) {
|
if ('tmid' in item && item.tmid) {
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
params = {
|
params = {
|
||||||
...params,
|
...params,
|
||||||
tmid: item.tmid,
|
tmid: item.tmid,
|
||||||
name: await getThreadName(this.rid, item.tmid, item._id),
|
name: await getThreadName(this.rid, item.tmid as string, item._id),
|
||||||
t: 'thread'
|
t: SubscriptionType.THREAD
|
||||||
};
|
};
|
||||||
navigation.push('RoomView', params);
|
navigation.push('RoomView', params);
|
||||||
} else {
|
} 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;
|
const { user, baseUrl, theme, useRealName } = this.props;
|
||||||
return (
|
return (
|
||||||
<Message
|
<Message
|
||||||
// @ts-ignore IMessage | TMessageModel?
|
item={message}
|
||||||
item={item}
|
|
||||||
baseUrl={baseUrl}
|
baseUrl={baseUrl}
|
||||||
user={user}
|
user={user}
|
||||||
timeFormat='MMM Do YYYY, h:mm:ss a'
|
timeFormat='MMM Do YYYY, h:mm:ss a'
|
||||||
isHeader
|
|
||||||
isThreadRoom
|
isThreadRoom
|
||||||
showAttachment={this.showAttachment}
|
showAttachment={this.showAttachment}
|
||||||
getCustomEmoji={this.getCustomEmoji}
|
getCustomEmoji={this.getCustomEmoji}
|
||||||
|
@ -289,6 +289,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
theme={theme}
|
theme={theme}
|
||||||
onPress={() => this.jumpToMessage({ item })}
|
onPress={() => this.jumpToMessage({ item })}
|
||||||
jumpToMessage={() => this.jumpToMessage({ item })}
|
jumpToMessage={() => this.jumpToMessage({ item })}
|
||||||
|
rid={message.rid}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue