[FIX] Search rooms (#468)
This commit is contained in:
parent
d5a4ead888
commit
2642a9e808
|
@ -540,6 +540,11 @@ const RocketChat = {
|
||||||
|
|
||||||
async search({ text, filterUsers = true, filterRooms = true }) {
|
async search({ text, filterUsers = true, filterRooms = true }) {
|
||||||
const searchText = text.trim();
|
const searchText = text.trim();
|
||||||
|
|
||||||
|
if (this.oldPromise) {
|
||||||
|
this.oldPromise('cancel');
|
||||||
|
}
|
||||||
|
|
||||||
if (searchText === '') {
|
if (searchText === '') {
|
||||||
delete this.oldPromise;
|
delete this.oldPromise;
|
||||||
return [];
|
return [];
|
||||||
|
@ -557,10 +562,6 @@ const RocketChat = {
|
||||||
const usernames = data.map(sub => sub.name);
|
const usernames = data.map(sub => sub.name);
|
||||||
try {
|
try {
|
||||||
if (data.length < 7) {
|
if (data.length < 7) {
|
||||||
if (this.oldPromise) {
|
|
||||||
this.oldPromise('cancel');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { users, rooms } = await Promise.race([
|
const { users, rooms } = await Promise.race([
|
||||||
RocketChat.spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms }),
|
RocketChat.spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms }),
|
||||||
new Promise((resolve, reject) => this.oldPromise = reject)
|
new Promise((resolve, reject) => this.oldPromise = reject)
|
||||||
|
@ -577,14 +578,13 @@ const RocketChat = {
|
||||||
...room,
|
...room,
|
||||||
search: true
|
search: true
|
||||||
})));
|
})));
|
||||||
|
|
||||||
delete this.oldPromise;
|
|
||||||
}
|
}
|
||||||
|
delete this.oldPromise;
|
||||||
return data;
|
return data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
return [];
|
return data;
|
||||||
|
// return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ export default class RoomsListView extends LoggedView {
|
||||||
|
|
||||||
renderSearchBar = () => {
|
renderSearchBar = () => {
|
||||||
if (Platform.OS === 'ios') {
|
if (Platform.OS === 'ios') {
|
||||||
return <SearchBox onChangeText={text => this.search(text)} testID='rooms-list-view-search' />;
|
return <SearchBox onChangeText={this.search} testID='rooms-list-view-search' />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue