From a9b3756a44ea367b609d23e387412d5b56a8557c Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 9 Jan 2024 10:25:32 +1100 Subject: [PATCH] Fixed UX around tapping link in messages which contain attachments --- .../ConversationVC+Interaction.swift | 23 ++++++++++++++++++- .../Message Cells/VisibleMessageCell.swift | 3 +++ .../General/Dictionary+Utilities.swift | 4 +++- .../Networking/HTTPError.swift | 2 ++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 08f1dc511..6bceb2a12 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -897,11 +897,30 @@ extension ConversationVC: return } + /// Takes the `cell` and a `targetView` and returns `true` if the user tapped a link in the cell body text instead + /// of the `targetView` + func handleLinkTapIfNeeded(cell: UITableViewCell, targetView: UIView?) -> Bool { + let locationInTargetView: CGPoint = cell.convert(cellLocation, to: targetView) + + guard + let visibleCell: VisibleMessageCell = cell as? VisibleMessageCell, + targetView?.bounds.contains(locationInTargetView) != true, + visibleCell.bodyTappableLabel?.containsLinks == true + else { return false } + + let tappableLabelPoint: CGPoint = cell.convert(cellLocation, to: visibleCell.bodyTappableLabel) + visibleCell.bodyTappableLabel?.handleTouch(at: tappableLabelPoint) + return true + } + switch cellViewModel.cellType { case .voiceMessage: viewModel.playOrPauseAudio(for: cellViewModel) case .mediaMessage: - guard let albumView: MediaAlbumView = (cell as? VisibleMessageCell)?.albumView else { return } + guard + let albumView: MediaAlbumView = (cell as? VisibleMessageCell)?.albumView, + !handleLinkTapIfNeeded(cell: cell, targetView: albumView) + else { return } // Figure out which of the media views was tapped let locationInAlbumView: CGPoint = cell.convert(cellLocation, to: albumView) @@ -982,6 +1001,7 @@ extension ConversationVC: case .audio: guard + !handleLinkTapIfNeeded(cell: cell, targetView: (cell as? VisibleMessageCell)?.documentView), let attachment: Attachment = cellViewModel.attachments?.first, let originalFilePath: String = attachment.originalFilePath else { return } @@ -993,6 +1013,7 @@ extension ConversationVC: case .genericAttachment: guard + !handleLinkTapIfNeeded(cell: cell, targetView: (cell as? VisibleMessageCell)?.documentView), let attachment: Attachment = cellViewModel.attachments?.first, let originalFilePath: String = attachment.originalFilePath else { return } diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index bee8273db..237add115 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -14,6 +14,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate { var albumView: MediaAlbumView? var quoteView: QuoteView? var linkPreviewView: LinkPreviewView? + var documentView: DocumentView? var bodyTappableLabel: TappableLabel? var voiceMessageView: VoiceMessageView? var audioStateChanged: ((TimeInterval, Bool) -> ())? @@ -471,6 +472,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate { albumView = nil quoteView = nil linkPreviewView = nil + documentView = nil bodyTappableLabel = nil // Handle the deleted state first (it's much simpler than the others) @@ -649,6 +651,7 @@ final class VisibleMessageCell: MessageCell, TappableLabelDelegate { // Document view let documentView = DocumentView(attachment: attachment, textColor: bodyLabelTextColor) + self.documentView = documentView stackView.addArrangedSubview(documentView) // Body text view diff --git a/SessionUtilitiesKit/General/Dictionary+Utilities.swift b/SessionUtilitiesKit/General/Dictionary+Utilities.swift index ee1fafd85..4c3dc59da 100644 --- a/SessionUtilitiesKit/General/Dictionary+Utilities.swift +++ b/SessionUtilitiesKit/General/Dictionary+Utilities.swift @@ -1,4 +1,6 @@ // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. +// +// stringlint:disable import Foundation @@ -8,7 +10,7 @@ public extension Dictionary { return "[ " + map { key, value in let keyDescription = String(describing: key) let valueDescription = String(describing: value) - let maxLength = 20 + let maxLength = 50 let truncatedValueDescription = valueDescription.count > maxLength ? valueDescription.prefix(maxLength) + "..." : valueDescription return keyDescription + " : " + truncatedValueDescription }.joined(separator: ", ") + " ]" diff --git a/SessionUtilitiesKit/Networking/HTTPError.swift b/SessionUtilitiesKit/Networking/HTTPError.swift index 7a3d2af08..91ce0d48a 100644 --- a/SessionUtilitiesKit/Networking/HTTPError.swift +++ b/SessionUtilitiesKit/Networking/HTTPError.swift @@ -1,4 +1,6 @@ // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. +// +// stringlint:disable import Foundation