mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
New async [MXRoom state:]: MXKSearchCellDataStoring: Replace initWithSearchResult by async cellDataWithSearchResult
This commit is contained in:
@@ -33,9 +33,11 @@
|
||||
[super destroy];
|
||||
}
|
||||
|
||||
- (void)convertHomeserverResultsIntoCells:(MXSearchRoomEventResults *)roomEventResults
|
||||
- (void)convertHomeserverResultsIntoCells:(MXSearchRoomEventResults *)roomEventResults onComplete:(dispatch_block_t)onComplete
|
||||
{
|
||||
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:self.mxSession];
|
||||
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
|
||||
// Convert the HS results into `RoomViewController` cells
|
||||
for (MXSearchResult *result in roomEventResults.results)
|
||||
@@ -43,48 +45,57 @@
|
||||
// Retrieve the local room data source thanks to the room identifier
|
||||
// Note: if no local room data source exist the result is ignored.
|
||||
NSString *roomId = result.result.roomId;
|
||||
UIFont *patternFont = nil;
|
||||
MXKRoomDataSource *roomDataSource;
|
||||
if (roomId)
|
||||
{
|
||||
dispatch_group_enter(group);
|
||||
|
||||
// Check whether the user knows this room to create the room data source if it doesn't exist.
|
||||
roomDataSource = [roomDataSourceManager roomDataSourceForRoom:roomId create:([self.mxSession roomWithRoomId:roomId])];
|
||||
if (roomDataSource)
|
||||
{
|
||||
// Prepare text font used to highlight the search pattern.
|
||||
patternFont = [roomDataSource.eventFormatter bingTextFont];
|
||||
|
||||
// Let the `RoomViewController` ecosystem do the job
|
||||
// The search result contains only room message events, no state events.
|
||||
// Thus, passing the current room state is not a huge problem. Only
|
||||
// the user display name and his avatar may be wrong.
|
||||
RoomBubbleCellData *cellData = [[RoomBubbleCellData alloc] initWithEvent:result.result andRoomState:roomDataSource.room.state andRoomDataSource:roomDataSource];
|
||||
if (cellData)
|
||||
[roomDataSourceManager roomDataSourceForRoom:roomId create:[self.mxSession roomWithRoomId:roomId] onComplete:^(MXKRoomDataSource *roomDataSource) {
|
||||
|
||||
if (roomDataSource)
|
||||
{
|
||||
// Highlight the search pattern
|
||||
[cellData highlightPatternInTextMessage:self.searchText withForegroundColor:kRiotColorGreen andFont:patternFont];
|
||||
|
||||
[cellDataArray insertObject:cellData atIndex:0];
|
||||
// Prepare text font used to highlight the search pattern.
|
||||
UIFont *patternFont = [roomDataSource.eventFormatter bingTextFont];
|
||||
|
||||
// Let the `RoomViewController` ecosystem do the job
|
||||
// The search result contains only room message events, no state events.
|
||||
// Thus, passing the current room state is not a huge problem. Only
|
||||
// the user display name and his avatar may be wrong.
|
||||
RoomBubbleCellData *cellData = [[RoomBubbleCellData alloc] initWithEvent:result.result andRoomState:roomDataSource.roomState andRoomDataSource:roomDataSource];
|
||||
if (cellData)
|
||||
{
|
||||
// Highlight the search pattern
|
||||
[cellData highlightPatternInTextMessage:self.searchText withForegroundColor:kRiotColorGreen andFont:patternFont];
|
||||
|
||||
[self->cellDataArray insertObject:cellData atIndex:0];
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
|
||||
// In case of successive messages from the same room,
|
||||
// we use the pagination flag to display the room name only on the first message.
|
||||
NSString *currentRoomId;
|
||||
for (RoomBubbleCellData *cellData in self->cellDataArray)
|
||||
{
|
||||
if (currentRoomId && [currentRoomId isEqualToString:cellData.roomId])
|
||||
{
|
||||
cellData.isPaginationFirstBubble = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
cellData.isPaginationFirstBubble = YES;
|
||||
currentRoomId = cellData.roomId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In case of successive messages from the same room,
|
||||
// we use the pagination flag to display the room name only on the first message.
|
||||
NSString *currentRoomId;
|
||||
for (RoomBubbleCellData *cellData in cellDataArray)
|
||||
{
|
||||
if (currentRoomId && [currentRoomId isEqualToString:cellData.roomId])
|
||||
{
|
||||
cellData.isPaginationFirstBubble = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
cellData.isPaginationFirstBubble = YES;
|
||||
currentRoomId = cellData.roomId;
|
||||
}
|
||||
}
|
||||
|
||||
onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
|
||||
Reference in New Issue
Block a user