mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-17 05:10:02 +02:00
Public rooms search: Replace the PublicRoomsDirectoryDataSource.filter by an array of strings PublicRoomsDirectoryDataSource.searchPatternsList.
This commit is contained in:
@@ -39,13 +39,14 @@
|
||||
|
||||
/**
|
||||
The filter being applied. Nil if there is no filter.
|
||||
A 'OR' search is made on the strings of the array.
|
||||
Setting a new value may trigger a request to the home server. So, the data source state
|
||||
may change to MXKDataSourceStatePreparing.
|
||||
*/
|
||||
@property (nonatomic) NSString *filter;
|
||||
@property (nonatomic) NSArray<NSString*> *searchPatternsList;
|
||||
|
||||
/**
|
||||
Public rooms of the directory that match `filter`.
|
||||
Public rooms of the directory that match `searchPatternsList`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray<MXPublicRoom*> *filteredRooms;
|
||||
|
||||
|
||||
@@ -38,11 +38,14 @@ double const kPublicRoomsDirectoryDataExpiration = 10;
|
||||
|
||||
@implementation PublicRoomsDirectoryDataSource
|
||||
|
||||
- (void)setFilter:(NSString *)searchTerm
|
||||
- (void)setSearchPatternsList:(NSArray<NSString *> *)newSearchPatternsList
|
||||
{
|
||||
if (![searchTerm isEqualToString:_filter])
|
||||
NSString *searchPatternsListString = [_searchPatternsList componentsJoinedByString:@""];
|
||||
NSString *newSearchPatternsListString = [newSearchPatternsList componentsJoinedByString:@""];
|
||||
|
||||
if (![newSearchPatternsListString isEqualToString:searchPatternsListString])
|
||||
{
|
||||
_filter = searchTerm;
|
||||
_searchPatternsList = newSearchPatternsList;
|
||||
[self refreshPublicRooms];
|
||||
}
|
||||
}
|
||||
@@ -114,16 +117,21 @@ double const kPublicRoomsDirectoryDataExpiration = 10;
|
||||
- (void)refreshFilteredPublicRooms
|
||||
{
|
||||
// Apply filter if any
|
||||
if (_filter)
|
||||
if (_searchPatternsList)
|
||||
{
|
||||
NSMutableArray *filteredRooms = [NSMutableArray array];
|
||||
for (MXPublicRoom *publicRoom in _rooms)
|
||||
{
|
||||
if ([filteredRooms indexOfObjectIdenticalTo:publicRoom] == NSNotFound)
|
||||
{
|
||||
if ([publicRoom.displayname rangeOfString:_filter options:NSCaseInsensitiveSearch].location != NSNotFound)
|
||||
// Do a OR search
|
||||
for (NSString *pattern in _searchPatternsList)
|
||||
{
|
||||
[filteredRooms addObject:publicRoom];
|
||||
if ([publicRoom.displayname rangeOfString:pattern options:NSCaseInsensitiveSearch].location != NSNotFound)
|
||||
{
|
||||
[filteredRooms addObject:publicRoom];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@
|
||||
// Manage the public room search results cell outside the recents.
|
||||
// Show the cell showing the public rooms directory search result
|
||||
// once a search is active
|
||||
if (_publicRoomsDirectoryDataSource.filter)
|
||||
if (_publicRoomsDirectoryDataSource.searchPatternsList)
|
||||
{
|
||||
directorySection = sectionIndex;
|
||||
sectionIndex++;
|
||||
@@ -682,17 +682,7 @@
|
||||
|
||||
if (_publicRoomsDirectoryDataSource)
|
||||
{
|
||||
if (patternsList)
|
||||
{
|
||||
// Search only on the first pattern
|
||||
// XXX: Why is it an array?
|
||||
_publicRoomsDirectoryDataSource.filter = patternsList[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
_publicRoomsDirectoryDataSource.filter = nil; // = patternsList
|
||||
}
|
||||
|
||||
_publicRoomsDirectoryDataSource.searchPatternsList = patternsList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,14 @@
|
||||
break;
|
||||
|
||||
case MXKDataSourceStateReady:
|
||||
{
|
||||
// Concatenate all patterns into one string
|
||||
NSString *filter = [publicRoomsDirectoryDataSource.searchPatternsList componentsJoinedByString:@" "];
|
||||
|
||||
self.titleLabel.text = NSLocalizedStringFromTable(@"directory_search_results_title", @"Vector", nil);
|
||||
self.descriptionLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"directory_search_results", @"Vector", nil),
|
||||
publicRoomsDirectoryDataSource.filteredRooms.count,
|
||||
publicRoomsDirectoryDataSource.filter];
|
||||
filter];
|
||||
|
||||
if (publicRoomsDirectoryDataSource.filteredRooms.count)
|
||||
{
|
||||
@@ -47,6 +51,7 @@
|
||||
self.chevronImageView.hidden = NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MXKDataSourceStateFailed:
|
||||
self.titleLabel.text = NSLocalizedStringFromTable(@"directory_searching_title", @"Vector", nil);
|
||||
|
||||
Reference in New Issue
Block a user