Use bubbleComponentWithLinkForEventId: in RoomDataSource.

This commit is contained in:
Doug 2021-09-27 18:43:53 +01:00
parent f44e1b098e
commit 66c92fbe03
2 changed files with 20 additions and 23 deletions

View file

@ -110,6 +110,14 @@ typedef NS_ENUM(NSInteger, RoomBubbleCellDataTag)
*/
- (NSInteger)firstVisibleComponentIndex;
/**
Returns the bubble component for the specified event ID, but only if that component
has detected a link in the event's body. Otherwise returns `nil`.
This will also return `nil` If URL previews have been disabled by the user.
*/
- (MXKRoomBubbleComponent *)bubbleComponentWithLinkForEventId:(NSString *)eventId;
#pragma mark - Show all reactions
- (BOOL)showAllReactionsForEvent:(NSString*)eventId;

View file

@ -1219,41 +1219,30 @@ const CGFloat kTypingCellHeight = 24;
// Use the link stored in the bubble component when opening the URL as we only
// store the sanitized URL in the preview data which may differ to the message content.
RoomBubbleCellData *cellData = [self cellDataOfEventWithEventId:eventID];
if (!cellData)
MXKRoomBubbleComponent *component = [cellData bubbleComponentWithLinkForEventId:eventID];
if (!component)
{
MXLogError(@"[RoomDataSource] Failed to open link: Unable to find bubble component.")
return;
}
NSInteger index = [cellData bubbleComponentIndexForEventId:eventID];
if (index == NSNotFound)
{
return;
}
MXKRoomBubbleComponent *component = cellData.bubbleComponents[index];
[UIApplication.sharedApplication vc_open:component.link completionHandler:nil];
}
- (void)didCloseURLPreviewView:(URLPreviewView *)previewView for:(NSString *)eventID in:(NSString *)roomID
{
RoomBubbleCellData *cellData = [self cellDataOfEventWithEventId:eventID];
if (!cellData)
{
return;
}
NSInteger index = [cellData bubbleComponentIndexForEventId:eventID];
if (index == NSNotFound)
{
return;
}
MXKRoomBubbleComponent *component = cellData.bubbleComponents[index];
// Remember that the user closed the preview so it isn't shown again.
[URLPreviewService.shared closePreviewFor:eventID in:roomID];
// Get the component to remove the URL preview from.
RoomBubbleCellData *cellData = [self cellDataOfEventWithEventId:eventID];
MXKRoomBubbleComponent *component = [cellData bubbleComponentWithLinkForEventId:eventID];
if (!component)
{
MXLogError(@"[RoomDataSource] Failed to close URL preview: Unable to find bubble component.")
return;
}
// Hide the preview, remove its data and refresh the cells.
component.showURLPreview = NO;
component.urlPreviewData = nil;