using database query instead of Rocketchat search api to get message search results
This commit is contained in:
parent
99ea5d8e2a
commit
9794734fa8
|
@ -12,7 +12,6 @@ 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';
|
||||||
|
@ -134,15 +133,15 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle encrypted rooms search messages
|
// Handle encrypted rooms search messages
|
||||||
searchMessages = async (searchText: string) => {
|
searchMessages = (searchText: string) => {
|
||||||
if (!searchText) {
|
if (!searchText) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// If it's a encrypted, room we'll search only on the local stored messages
|
// If it's a encrypted, room we'll search only on the local stored messages
|
||||||
|
const db = database.active;
|
||||||
|
const likeString = sanitizeLikeString(searchText);
|
||||||
if (this.encrypted) {
|
if (this.encrypted) {
|
||||||
const db = database.active;
|
|
||||||
const messagesCollection = db.get('messages');
|
const messagesCollection = db.get('messages');
|
||||||
const likeString = sanitizeLikeString(searchText);
|
|
||||||
return messagesCollection
|
return messagesCollection
|
||||||
.query(
|
.query(
|
||||||
// Messages of this room
|
// Messages of this room
|
||||||
|
@ -153,12 +152,15 @@ 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 result = await RocketChat.searchMessages(this.rid, searchText, QUERY_SIZE, this.offset);
|
const whereClause = [Q.where('rid', this.rid), Q.where('msg', Q.like(`%${likeString}%`)), Q.experimentalTake(QUERY_SIZE)] as (
|
||||||
if (result.success) {
|
| Q.WhereDescription
|
||||||
return result.messages;
|
| Q.Or
|
||||||
}
|
)[];
|
||||||
|
const messagesCollection = db
|
||||||
return [];
|
.get('messages')
|
||||||
|
.query(...whereClause)
|
||||||
|
.fetch();
|
||||||
|
return messagesCollection;
|
||||||
};
|
};
|
||||||
getMessages = async (searchText: string, debounced?: boolean) => {
|
getMessages = async (searchText: string, debounced?: boolean) => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue