Skip to content

Commit

Permalink
[FIX] Search rooms (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello committed Sep 28, 2018
1 parent 7fb87ae commit 8ebe221
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ const RocketChat = {

async search({ text, filterUsers = true, filterRooms = true }) {
const searchText = text.trim();

if (this.oldPromise) {
this.oldPromise('cancel');
}

if (searchText === '') {
delete this.oldPromise;
return [];
Expand All @@ -557,10 +562,6 @@ const RocketChat = {
const usernames = data.map(sub => sub.name);
try {
if (data.length < 7) {
if (this.oldPromise) {
this.oldPromise('cancel');
}

const { users, rooms } = await Promise.race([
RocketChat.spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms }),
new Promise((resolve, reject) => this.oldPromise = reject)
Expand All @@ -577,14 +578,13 @@ const RocketChat = {
...room,
search: true
})));

delete this.oldPromise;
}

delete this.oldPromise;
return data;
} catch (e) {
console.warn(e);
return [];
return data;
// return [];
}
},

Expand Down
2 changes: 1 addition & 1 deletion app/views/RoomsListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export default class RoomsListView extends LoggedView {

renderSearchBar = () => {
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' />;
}
}

Expand Down

0 comments on commit 8ebe221

Please sign in to comment.