Browse Source

also don't react on taps on links, numbers, commands if editing mode is enabled

cyberta 4 years ago
parent
commit
343dc7bf24

+ 13 - 8
deltachat-ios/Chat/ChatViewController.swift

@@ -1194,7 +1194,7 @@ class ChatViewController: UITableViewController {
 
     func handleSelection(indexPath: IndexPath) -> Bool {
         if tableView.isEditing {
-            if (tableView.indexPathsForSelectedRows?.contains(indexPath) ?? false) {
+            if tableView.indexPathsForSelectedRows?.contains(indexPath) ?? false {
                 tableView.deselectRow(at: indexPath, animated: false)
             } else {
                 tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
@@ -1228,23 +1228,28 @@ extension ChatViewController: BaseMessageCellDelegate {
         }
     }
 
-    @objc func phoneNumberTapped(number: String) {
-        if handleUIMenu() { return }
+    @objc func phoneNumberTapped(number: String, indexPath: IndexPath) {
+        if handleUIMenu() || handleSelection(indexPath: indexPath) {
+            return
+        }
         logger.debug("phone number tapped \(number)")
     }
 
-    @objc func commandTapped(command: String) {
-        if handleUIMenu() { return }
+    @objc func commandTapped(command: String, indexPath: IndexPath) {
+        if handleUIMenu() || handleSelection(indexPath: indexPath) {
+            return
+        }
         logger.debug("command tapped \(command)")
     }
 
-    @objc func urlTapped(url: URL) {
-        if handleUIMenu() { return }
+    @objc func urlTapped(url: URL, indexPath: IndexPath) {
+        if handleUIMenu() || handleSelection(indexPath: indexPath) {
+            return
+        }
         if Utils.isEmail(url: url) {
             logger.debug("tapped on contact")
             let email = Utils.getEmailFrom(url)
             self.askToChatWith(email: email)
-            ///TODO: implement handling
         } else {
             UIApplication.shared.open(url)
         }

+ 11 - 6
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -438,12 +438,17 @@ extension BaseMessageCell: MessageLabelDelegate {
     public func didSelectDate(_ date: Date) {}
 
     public func didSelectPhoneNumber(_ phoneNumber: String) {
-        baseDelegate?.phoneNumberTapped(number: phoneNumber)
+        if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
+            baseDelegate?.phoneNumberTapped(number: phoneNumber, indexPath: indexPath)
+        }
+
     }
 
     public func didSelectURL(_ url: URL) {
-        logger.debug("did select URL")
-        baseDelegate?.urlTapped(url: url)
+        if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
+            logger.debug("did select URL")
+            baseDelegate?.urlTapped(url: url, indexPath: indexPath)
+        }
     }
 
     public func didSelectTransitInformation(_ transitInformation: [String: String]) {}
@@ -458,9 +463,9 @@ extension BaseMessageCell: MessageLabelDelegate {
 // MARK: - BaseMessageCellDelegate
 // this delegate contains possible events from base cells or from derived cells
 public protocol BaseMessageCellDelegate: class {
-    func commandTapped(command: String) // `/command`
-    func phoneNumberTapped(number: String)
-    func urlTapped(url: URL) // url is eg. `https://foo.bar`
+    func commandTapped(command: String, indexPath: IndexPath) // `/command`
+    func phoneNumberTapped(number: String, indexPath: IndexPath)
+    func urlTapped(url: URL, indexPath: IndexPath) // url is eg. `https://foo.bar`
     func imageTapped(indexPath: IndexPath)
     func avatarTapped(indexPath: IndexPath)
     func textTapped(indexPath: IndexPath)

+ 3 - 3
deltachat-ios/Controller/MailboxViewController.swift

@@ -22,9 +22,9 @@ class MailboxViewController: ChatViewController {
         askToChat(messageId: messageIds[indexPath.row])
     }
 
-    override func phoneNumberTapped(number: String) {}
-    override func commandTapped(command: String) {}
-    override func urlTapped(url: URL) {}
+    override func phoneNumberTapped(number: String, indexPath: IndexPath) {}
+    override func commandTapped(command: String, indexPath: IndexPath) {}
+    override func urlTapped(url: URL, indexPath: IndexPath) {}
     override func imageTapped(indexPath: IndexPath) {
         askToChat(messageId: messageIds[indexPath.row])
     }