Merge pull request #4538 from vector-im/doug/4537_fix_show_directory_view_controller_rooms_count

Fix duplicate results in the rooms directory.
This commit is contained in:
Doug 2021-07-08 16:34:36 +01:00 committed by GitHub
commit 0ebb4535e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 13 deletions

View file

@ -12,6 +12,7 @@ Changes to be released in next version
* More fixes to Main.storyboard layout on iPhone 12 Pro Max (#4527) * More fixes to Main.storyboard layout on iPhone 12 Pro Max (#4527)
* Fix crash on Apple Silicon Macs. * Fix crash on Apple Silicon Macs.
* Media Picker: Generate video thumbnails with the correct orientation (#4515). * Media Picker: Generate video thumbnails with the correct orientation (#4515).
* Directory List (pop-up one): Fix duplicate rooms being shown (#4537).
⚠️ API Changes ⚠️ API Changes
* *

View file

@ -54,20 +54,20 @@
self.titleLabel.text = NSLocalizedStringFromTable(@"directory_search_results_title", @"Vector", nil); self.titleLabel.text = NSLocalizedStringFromTable(@"directory_search_results_title", @"Vector", nil);
// Do we need to display like ">20 results found" or "18 results found"? // Do we need to display like ">20 results found" or "18 results found"?
NSString *descriptionLabel = (publicRoomsDirectoryDataSource.moreThanRoomsCount && publicRoomsDirectoryDataSource.roomsCount > 0) ? NSLocalizedStringFromTable(@"directory_search_results_more_than", @"Vector", nil) : NSLocalizedStringFromTable(@"directory_search_results", @"Vector", nil); NSString *descriptionLabel = (publicRoomsDirectoryDataSource.searchResultsCountIsLimited && publicRoomsDirectoryDataSource.searchResultsCount > 0) ? NSLocalizedStringFromTable(@"directory_search_results_more_than", @"Vector", nil) : NSLocalizedStringFromTable(@"directory_search_results", @"Vector", nil);
self.descriptionLabel.text = [NSString stringWithFormat:descriptionLabel, self.descriptionLabel.text = [NSString stringWithFormat:descriptionLabel,
publicRoomsDirectoryDataSource.roomsCount, publicRoomsDirectoryDataSource.searchResultsCount,
publicRoomsDirectoryDataSource.searchPattern]; publicRoomsDirectoryDataSource.searchPattern];
} }
else else
{ {
self.titleLabel.text = NSLocalizedStringFromTable(@"directory_cell_title", @"Vector", nil); self.titleLabel.text = NSLocalizedStringFromTable(@"directory_cell_title", @"Vector", nil);
self.descriptionLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"directory_cell_description", @"Vector", nil), self.descriptionLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"directory_cell_description", @"Vector", nil),
publicRoomsDirectoryDataSource.roomsCount]; publicRoomsDirectoryDataSource.searchResultsCount];
} }
if (publicRoomsDirectoryDataSource.roomsCount) if (publicRoomsDirectoryDataSource.searchResultsCount)
{ {
self.userInteractionEnabled = YES; self.userInteractionEnabled = YES;
self.chevronImageView.hidden = NO; self.chevronImageView.hidden = NO;

View file

@ -62,11 +62,16 @@
@property (nonatomic, readonly) NSString *directoryServerDisplayname; @property (nonatomic, readonly) NSString *directoryServerDisplayname;
/** /**
The number of public rooms matching `searchPattern`. The number of public rooms that have been fetched so far.
It is accurate only if 'moreThanRoomsCount' is NO.
*/ */
@property (nonatomic, readonly) NSUInteger roomsCount; @property (nonatomic, readonly) NSUInteger roomsCount;
/**
The total number of public rooms matching `searchPattern`.
It is accurate only if 'searchResultsCountIsLimited' is NO.
*/
@property (nonatomic, readonly) NSUInteger searchResultsCount;
/** /**
In case of search with a lot of matching public rooms, we cannot return an accurate In case of search with a lot of matching public rooms, we cannot return an accurate
value except by paginating the full list of rooms, which is not expected. value except by paginating the full list of rooms, which is not expected.
@ -74,7 +79,7 @@
This flag indicates that we know that there is more matching rooms than we got This flag indicates that we know that there is more matching rooms than we got
so far. so far.
*/ */
@property (nonatomic, readonly) BOOL moreThanRoomsCount; @property (nonatomic, readonly) BOOL searchResultsCountIsLimited;
/** /**
The maximum number of public rooms to retrieve during a pagination. The maximum number of public rooms to retrieve during a pagination.

View file

@ -165,6 +165,11 @@ static NSString *const kNSFWKeyword = @"nsfw";
} }
} }
- (NSUInteger)roomsCount
{
return rooms.count;
}
- (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession - (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession
{ {
NSIndexPath *indexPath = nil; NSIndexPath *indexPath = nil;
@ -217,8 +222,8 @@ static NSString *const kNSFWKeyword = @"nsfw";
// Reset all pagination vars // Reset all pagination vars
[rooms removeAllObjects]; [rooms removeAllObjects];
nextBatch = nil; nextBatch = nil;
_roomsCount = 0; _searchResultsCount = 0;
_moreThanRoomsCount = NO; _searchResultsCountIsLimited = NO;
_hasReachedPaginationEnd = NO; _hasReachedPaginationEnd = NO;
} }
@ -264,14 +269,14 @@ static NSString *const kNSFWKeyword = @"nsfw";
if (!self->_searchPattern) if (!self->_searchPattern)
{ {
// When there is no search, we can use totalRoomCountEstimate returned by the server // When there is no search, we can use totalRoomCountEstimate returned by the server
self->_roomsCount = publicRoomsResponse.totalRoomCountEstimate; self->_searchResultsCount = publicRoomsResponse.totalRoomCountEstimate;
self->_moreThanRoomsCount = NO; self->_searchResultsCountIsLimited = NO;
} }
else else
{ {
// Else we can only display something like ">20 matching rooms" // Else we can only display something like ">20 matching rooms"
self->_roomsCount = self->rooms.count; self->_searchResultsCount = self->rooms.count;
self->_moreThanRoomsCount = publicRoomsResponse.nextBatch ? YES : NO; self->_searchResultsCountIsLimited = publicRoomsResponse.nextBatch ? YES : NO;
} }
// Detect pagination end // Detect pagination end