2015-12-31 15:12:32 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-12-31 15:12:32 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RoomSearchDataSource.h"
|
|
|
|
|
|
|
|
#import "RoomBubbleCellData.h"
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2021-10-26 15:42:33 +00:00
|
|
|
#import "GeneratedInterface-Swift.h"
|
2016-09-28 11:26:06 +00:00
|
|
|
|
2017-03-09 10:18:18 +00:00
|
|
|
#import "MXKRoomBubbleTableViewCell+Riot.h"
|
2016-09-28 07:38:49 +00:00
|
|
|
|
2015-12-31 15:12:32 +00:00
|
|
|
@interface RoomSearchDataSource ()
|
|
|
|
{
|
|
|
|
MXKRoomDataSource *roomDataSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomSearchDataSource
|
|
|
|
|
2016-09-29 09:47:02 +00:00
|
|
|
- (instancetype)initWithRoomDataSource:(MXKRoomDataSource *)roomDataSource2
|
2015-12-31 15:12:32 +00:00
|
|
|
{
|
2016-10-06 08:56:52 +00:00
|
|
|
self = [super initWithMatrixSession:roomDataSource2.mxSession];
|
2015-12-31 15:12:32 +00:00
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
roomDataSource = roomDataSource2;
|
2016-10-06 08:56:52 +00:00
|
|
|
|
|
|
|
// The messages search is limited to the room data.
|
|
|
|
self.roomEventFilter.rooms = @[roomDataSource.roomId];
|
2015-12-31 15:12:32 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-06-20 12:16:13 +00:00
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
roomDataSource = nil;
|
|
|
|
|
|
|
|
[super destroy];
|
|
|
|
}
|
|
|
|
|
2018-07-20 13:27:54 +00:00
|
|
|
- (void)convertHomeserverResultsIntoCells:(MXSearchRoomEventResults *)roomEventResults onComplete:(dispatch_block_t)onComplete
|
2015-12-31 15:12:32 +00:00
|
|
|
{
|
2016-09-28 11:26:06 +00:00
|
|
|
// Prepare text font used to highlight the search pattern.
|
|
|
|
UIFont *patternFont = [roomDataSource.eventFormatter bingTextFont];
|
|
|
|
|
2015-12-31 15:12:32 +00:00
|
|
|
// Convert the HS results into `RoomViewController` cells
|
|
|
|
for (MXSearchResult *result in roomEventResults.results)
|
|
|
|
{
|
|
|
|
// 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.
|
2018-07-20 08:34:54 +00:00
|
|
|
RoomBubbleCellData *cellData = [[RoomBubbleCellData alloc] initWithEvent:result.result andRoomState:roomDataSource.roomState andRoomDataSource:roomDataSource];
|
2015-12-31 15:12:32 +00:00
|
|
|
if (cellData)
|
|
|
|
{
|
2016-09-28 11:26:06 +00:00
|
|
|
// Highlight the search pattern
|
2019-01-11 10:45:27 +00:00
|
|
|
[cellData highlightPatternInTextMessage:self.searchText withForegroundColor:ThemeService.shared.theme.tintColor andFont:patternFont];
|
2018-08-03 15:01:53 +00:00
|
|
|
|
|
|
|
// Use profile information as data to display
|
|
|
|
MXSearchUserProfile *userProfile = result.context.profileInfo[result.result.sender];
|
|
|
|
cellData.senderDisplayName = userProfile.displayName;
|
|
|
|
cellData.senderAvatarUrl = userProfile.avatarUrl;
|
|
|
|
|
2015-12-31 15:12:32 +00:00
|
|
|
[cellDataArray insertObject:cellData atIndex:0];
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 13:27:54 +00:00
|
|
|
|
|
|
|
onComplete();
|
2015-12-31 15:12:32 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 07:38:49 +00:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
|
|
|
|
// Finalize cell view customization here
|
|
|
|
if ([cell isKindOfClass:MXKRoomBubbleTableViewCell.class])
|
|
|
|
{
|
|
|
|
MXKRoomBubbleTableViewCell *bubbleCell = (MXKRoomBubbleTableViewCell*)cell;
|
|
|
|
|
|
|
|
// Display date for each message
|
|
|
|
[bubbleCell addDateLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:12:32 +00:00
|
|
|
@end
|