Skip to content

Commit

Permalink
[FIX] Spotlight returning duplicated entries (#2805)
Browse files Browse the repository at this point in the history
* Update rocketchat.js

* Updated search function

* Minor improvements

* Remove atIndex

* Add remove logic to remove duplicate data from response

Co-authored-by: Diego Mello <[email protected]>
  • Loading branch information
gerzonc and diegolmello authored Jan 20, 2021
1 parent 61bc2a4 commit d83631d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
24 changes: 14 additions & 10 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ const RocketChat = {
fname: sub.fname,
avatarETag: sub.avatarETag,
t: sub.t,
encrypted: sub.encrypted,
search: true
encrypted: sub.encrypted
};
}
return sub;
Expand All @@ -648,7 +647,7 @@ const RocketChat = {
return [];
}

let data = await this.localSearch({ text, filterUsers, filterRooms });
const data = await this.localSearch({ text, filterUsers, filterRooms });

const usernames = data.map(sub => sub.name);
try {
Expand All @@ -658,13 +657,18 @@ const RocketChat = {
new Promise((resolve, reject) => this.oldPromise = reject)
]);
if (filterUsers) {
data = data.concat(users.map(user => ({
...user,
rid: user.username,
name: user.username,
t: 'd',
search: true
})));
users
.filter((item1, index) => users.findIndex(item2 => item2._id === item1._id) === index) // Remove duplicated data from response
.filter(user => !data.some(sub => user.username === sub.name)) // Make sure to remove users already on local database
.forEach((user) => {
data.push({
...user,
rid: user.username,
name: user.username,
t: 'd',
search: true
});
});
}
if (filterRooms) {
rooms.forEach((room) => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/assorted/05-joinpublicroom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const room = data.channels.detoxpublic.name;

async function navigateToRoom() {
await searchRoom(room);
await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toBeVisible().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap();
await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeVisible().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).tap();
await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000);
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/assorted/08-joinprotectedroom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const joinCode = data.channels.detoxpublicprotected.joinCode

async function navigateToRoom() {
await searchRoom(room);
await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toBeVisible().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap();
await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeVisible().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).tap();
await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000);
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/onboarding/06-roomslist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Rooms list screen', () => {
});

it('should have room item', async() => {
await expect(element(by.id('rooms-list-view-item-general')).atIndex(0)).toExist();
await expect(element(by.id('rooms-list-view-item-general'))).toExist();
});

// Render - Header
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/room/01-createroom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ describe('Create room screen', () => {

it('should select/unselect user', async() => {
// Spotlight issues
await element(by.id('select-users-view-item-rocket.cat')).atIndex(0).tap();
await element(by.id('select-users-view-item-rocket.cat')).tap();
await waitFor(element(by.id('selected-user-rocket.cat'))).toBeVisible().withTimeout(10000);
await element(by.id('selected-user-rocket.cat')).tap();
await waitFor(element(by.id('selected-user-rocket.cat'))).toBeNotVisible().withTimeout(10000);
// Spotlight issues
await element(by.id('select-users-view-item-rocket.cat')).atIndex(0).tap();
await element(by.id('select-users-view-item-rocket.cat')).tap();
await waitFor(element(by.id('selected-user-rocket.cat'))).toBeVisible().withTimeout(10000);
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/room/03-roomactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ async function navigateToRoomActions(type) {
room = data.groups.private.name;
}
await searchRoom(room);
await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toExist().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap();
await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toExist().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).tap();
await waitFor(element(by.id('room-view'))).toExist().withTimeout(2000);
await element(by.id('room-view-header-actions')).tap();
await waitFor(element(by.id('room-actions-view'))).toExist().withTimeout(5000);
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/room/04-roominfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ async function navigateToRoomInfo(type) {
room = privateRoomName;
}
await searchRoom(room);
await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toExist().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap();
await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toExist().withTimeout(60000);
await element(by.id(`rooms-list-view-item-${ room }`)).tap();
await waitFor(element(by.id('room-view'))).toExist().withTimeout(2000);
await element(by.id('room-view-header-actions')).tap();
await waitFor(element(by.id('room-actions-view'))).toExist().withTimeout(5000);
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@
"build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11 Pro"
"type": "iPhone 11 Pro",
"os": "13.7"
}
},
"ios.sim.release": {
"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/Rocket.Chat Experimental.app",
"build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Release -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11 Pro"
"type": "iPhone 11 Pro",
"os": "13.7"
},
"artifacts": {
"plugins": {
Expand Down

0 comments on commit d83631d

Please sign in to comment.