[FIX] Search in Rooms List crashes Android app (#4546)

* [FIX] Search in Rooms List crashes Android app

* back to previous search

* change the method/searchlocal
This commit is contained in:
Reinaldo Neto 2022-09-22 22:39:52 -03:00 committed by GitHub
parent 9d69c10bbd
commit e10de8b209
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -3,12 +3,12 @@ import { Q } from '@nozbe/watermelondb';
import { sanitizeLikeString } from '../database/utils';
import database from '../database/index';
import { spotlight } from '../services/restApi';
import { ISearch, ISearchLocal, SubscriptionType, TSubscriptionModel } from '../../definitions';
import { ISearch, ISearchLocal, SubscriptionType } from '../../definitions';
import { isGroupChat } from './helpers';
let debounce: null | ((reason: string) => void) = null;
export const localSearch = async ({ text = '', filterUsers = true, filterRooms = true }): Promise<TSubscriptionModel[]> => {
export const localSearch = async ({ text = '', filterUsers = true, filterRooms = true }): Promise<ISearchLocal[]> => {
const searchText = text.trim();
const db = database.active;
const likeString = sanitizeLikeString(searchText);
@ -26,7 +26,20 @@ export const localSearch = async ({ text = '', filterUsers = true, filterRooms =
subscriptions = subscriptions.filter(item => item.t !== 'd' || isGroupChat(item));
}
const search = subscriptions.slice(0, 7);
const search = subscriptions.slice(0, 7).map(item => ({
avatarETag: item.avatarETag,
rid: item.rid,
name: item.name,
t: item.t,
fname: item.fname,
encrypted: item.encrypted,
lastMessage: item.lastMessage,
_id: item._id,
status: item.status,
username: item.usernames,
outside: false,
search: true
})) as ISearchLocal[];
return search;
};