getting search data from server then converting it into the format as required for message rendering
This commit is contained in:
parent
a0c418d9fd
commit
fb3c6d8069
|
@ -12,6 +12,7 @@ import RCTextInput from '../../containers/TextInput';
|
||||||
import ActivityIndicator from '../../containers/ActivityIndicator';
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
||||||
import Markdown from '../../containers/markdown';
|
import Markdown from '../../containers/markdown';
|
||||||
import debounce from '../../utils/debounce';
|
import debounce from '../../utils/debounce';
|
||||||
|
import RocketChat from '../../lib/rocketchat';
|
||||||
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 { IMessage } from '../../containers/message/interfaces';
|
||||||
|
@ -32,6 +33,7 @@ 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';
|
||||||
|
|
||||||
const QUERY_SIZE = 50;
|
const QUERY_SIZE = 50;
|
||||||
|
|
||||||
|
@ -133,7 +135,7 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle encrypted rooms search messages
|
// Handle encrypted rooms search messages
|
||||||
searchMessages = (searchText: string) => {
|
searchMessages = async (searchText: string) => {
|
||||||
if (!searchText) {
|
if (!searchText) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -152,15 +154,29 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
.fetch();
|
.fetch();
|
||||||
}
|
}
|
||||||
// If it's not a encrypted room, search messages on the server
|
// If it's not a encrypted room, search messages on the server
|
||||||
const whereClause = [Q.where('rid', this.rid), Q.where('msg', Q.like(`%${likeString}%`)), Q.experimentalTake(QUERY_SIZE)] as (
|
const result = await RocketChat.searchMessages(this.rid, searchText, QUERY_SIZE, this.offset);
|
||||||
| Q.WhereDescription
|
if (result.success) {
|
||||||
| Q.Or
|
const urlRenderMessages = result.messages?.map(message => {
|
||||||
)[];
|
// @ts-ignore
|
||||||
const messagesCollection = db
|
if (message.urls.length > 0) {
|
||||||
.get('messages')
|
message.urls = message.urls?.map((url, index) => {
|
||||||
.query(...whereClause)
|
if (url.meta !== undefined) {
|
||||||
.fetch();
|
return {
|
||||||
return messagesCollection;
|
_id: index,
|
||||||
|
title: url.meta.pageTitle,
|
||||||
|
description: url.meta.ogDescription,
|
||||||
|
image: url.meta.ogImage,
|
||||||
|
url: url.url
|
||||||
|
} as IUrl;
|
||||||
|
}
|
||||||
|
return {} as IUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
});
|
||||||
|
return urlRenderMessages;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
};
|
};
|
||||||
getMessages = async (searchText: string, debounced?: boolean) => {
|
getMessages = async (searchText: string, debounced?: boolean) => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue