diff --git a/lib/shared/search-utils.js b/lib/shared/search-utils.js --- a/lib/shared/search-utils.js +++ b/lib/shared/search-utils.js @@ -97,25 +97,28 @@ const nonFriends = []; const blockedUsers = []; - const friendsAndContainingThreadMembers = []; + const friends = []; + const containingThreadMembers = []; + const parentThreadMembers = []; for (const userResult of results) { const relationshipStatus = userResult.relationshipStatus; - if ( - userResult.isMemberOfContainingThread && - !blockedRelationshipsStatuses.has(relationshipStatus) - ) { - friendsAndContainingThreadMembers.unshift(userResult); - } else if (relationshipStatus === userRelationshipStatus.FRIEND) { - friendsAndContainingThreadMembers.push(userResult); - } else if (blockedRelationshipsStatuses.has(relationshipStatus)) { + if (blockedRelationshipsStatuses.has(relationshipStatus)) { blockedUsers.push(userResult); + } else if (userResult.isMemberOfParentThread) { + parentThreadMembers.push(userResult); + } else if (userResult.isMemberOfContainingThread) { + containingThreadMembers.push(userResult); + } else if (relationshipStatus === userRelationshipStatus.FRIEND) { + friends.push(userResult); } else { nonFriends.push(userResult); } } - const sortedResults = friendsAndContainingThreadMembers + const sortedResults = parentThreadMembers + .concat(containingThreadMembers) + .concat(friends) .concat(nonFriends) .concat(blockedUsers);