Browse Source

move to message on tap on quote

cyberta 4 years ago
parent
commit
551401a0b7

+ 23 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -400,6 +400,18 @@ class ChatViewController: UITableViewController {
         }
     }
 
+    func highlightCell() {
+        if let indexpath = highlightedCell {
+            tableView.allowsSelection = true
+            tableView.selectRow(at: indexpath, animated: true, scrollPosition: .middle)
+            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
+                self.tableView.deselectRow(at: indexpath, animated: true)
+                self.tableView.allowsSelection = false
+            })
+            highlightedCell = nil
+        }
+    }
+
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let messageId = messageIds[indexPath.row]
         let message = DcMsg(id: messageId)
@@ -1069,6 +1081,17 @@ class ChatViewController: UITableViewController {
 // MARK: - BaseMessageCellDelegate
 extension ChatViewController: BaseMessageCellDelegate {
 
+    @objc func quoteTapped(indexPath: IndexPath) {
+        logger.debug("quoteTapped")
+        _ = handleUIMenu()
+        let msg = DcMsg(id: messageIds[indexPath.row])
+        if let quoteMsg = msg.quoteMessage,
+           let index = messageIds.firstIndex(of: quoteMsg.id) {
+            let indexPath = IndexPath(row: index, section: 0)
+            tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
+        }
+    }
+
     @objc func textTapped(indexPath: IndexPath) {
         _ = handleUIMenu()
     }

+ 12 - 0
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -192,6 +192,11 @@ public class BaseMessageCell: UITableViewCell {
         let messageLabelGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
         gestureRecognizer.numberOfTapsRequired = 1
         messageLabel.addGestureRecognizer(messageLabelGestureRecognizer)
+
+        let quoteViewGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onQuoteTapped))
+        quoteViewGestureRecognizer.numberOfTapsRequired = 1
+        quoteView.addGestureRecognizer(quoteViewGestureRecognizer)
+
     }
 
     @objc
@@ -210,6 +215,12 @@ public class BaseMessageCell: UITableViewCell {
         }
     }
 
+    @objc func onQuoteTapped() {
+        if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
+            baseDelegate?.quoteTapped(indexPath: indexPath)
+        }
+    }
+
     // update classes inheriting BaseMessageCell first before calling super.update(...)
     func update(msg: DcMsg, messageStyle: UIRectCorner, isAvatarVisible: Bool, isGroup: Bool) {
         if msg.isFromCurrentSender {
@@ -430,4 +441,5 @@ public protocol BaseMessageCellDelegate: class {
     func imageTapped(indexPath: IndexPath)
     func avatarTapped(indexPath: IndexPath)
     func textTapped(indexPath: IndexPath)
+    func quoteTapped(indexPath: IndexPath)
 }