diff --git a/Config/BWIBuildSettings.swift b/Config/BWIBuildSettings.swift index 0cc19fc8a..a68e9d1d1 100644 --- a/Config/BWIBuildSettings.swift +++ b/Config/BWIBuildSettings.swift @@ -557,4 +557,7 @@ class BWIBuildSettings: NSObject { // MARK: - Maintenance var enableMaintenanceInfoOnWelcomeScreen = false + + // MARK: User Search + var sortUserSearchResultsAlphabetically = true } diff --git a/Riot/Modules/Contacts/DataSources/ContactsDataSource.m b/Riot/Modules/Contacts/DataSources/ContactsDataSource.m index 4381ee27e..cae9cc66c 100644 --- a/Riot/Modules/Contacts/DataSources/ContactsDataSource.m +++ b/Riot/Modules/Contacts/DataSources/ContactsDataSource.m @@ -215,8 +215,19 @@ self->filteredMatrixContacts = [NSMutableArray arrayWithCapacity:userSearchResponse.results.count]; + NSArray *sortedArray; + + if (BWIBuildSettings.shared.sortUserSearchResultsAlphabetically) { + sortedArray = [userSearchResponse.results sortedArrayUsingComparator:^NSComparisonResult(MXUser *a, MXUser *b) { + return [a.displayname caseInsensitiveCompare:b.displayname]; + }]; + } else { + sortedArray = userSearchResponse.results; + } + + // Keep the response order as the hs ordered users by relevance - for (MXUser *mxUser in userSearchResponse.results) + for (MXUser *mxUser in sortedArray) { MXKContact *contact = [[MXKContact alloc] initMatrixContactWithDisplayName:mxUser.displayname andMatrixID:mxUser.userId]; [self->filteredMatrixContacts addObject:contact];