mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Use bubbleComponentWithLinkForEventId: in RoomDataSource.
This commit is contained in:
parent
f44e1b098e
commit
66c92fbe03
2 changed files with 20 additions and 23 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue