Преглед изворни кода

ask to start chat on tap on a contact request message

cyberta пре 5 година
родитељ
комит
5c82cb4260

+ 6 - 2
deltachat-ios/Controller/ChatViewController.swift

@@ -789,7 +789,7 @@ extension ChatViewController: MessagesLayoutDelegate {
 
 // MARK: - MessageCellDelegate
 extension ChatViewController: MessageCellDelegate {
-    func didTapMessage(in cell: MessageCollectionViewCell) {
+    @objc func didTapMessage(in cell: MessageCollectionViewCell) {
         if let indexPath = messagesCollectionView.indexPath(for: cell) {
             let message = messageList[indexPath.section]
 
@@ -824,7 +824,7 @@ extension ChatViewController: MessageCellDelegate {
         }
     }
 
-    func didTapAvatar(in _: MessageCollectionViewCell) {
+    @objc func didTapAvatar(in _: MessageCollectionViewCell) {
         logger.info("Avatar tapped")
     }
 
@@ -835,6 +835,10 @@ extension ChatViewController: MessageCellDelegate {
     @objc(didTapCellBottomLabelIn:) func didTapCellBottomLabel(in _: MessageCollectionViewCell) {
         print("Bottom label tapped")
     }
+
+    @objc func didTapBackground(in cell: MessageCollectionViewCell) {
+        print("background of message tapped")
+    }
 }
 
 // MARK: - MessageLabelDelegate

+ 32 - 0
deltachat-ios/Controller/MailboxViewController.swift

@@ -1,4 +1,5 @@
 import UIKit
+import MessageKit
 
 class MailboxViewController: ChatViewController {
 
@@ -21,4 +22,35 @@ class MailboxViewController: ChatViewController {
         }
     }
 
+    override func didTapMessage(in cell: MessageCollectionViewCell) {
+        askToChat(cell: cell)
+    }
+
+    override func didTapCellTopLabel(in cell: MessageCollectionViewCell) {
+        askToChat(cell: cell)
+    }
+
+    override func didTapAvatar(in cell: MessageCollectionViewCell) {
+        askToChat(cell: cell)
+    }
+
+    override func didTapBackground(in cell: MessageCollectionViewCell) {
+        askToChat(cell: cell)
+    }
+
+
+    private func askToChat(cell: MessageCollectionViewCell) {
+        if let indexPath = messagesCollectionView.indexPath(for: cell) {
+
+            let message = messageList[indexPath.section]
+            let dcContact = message.fromContact
+            let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr), message: nil, preferredStyle: .actionSheet)
+            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+                let chat = message.createChat()
+                self.coordinator?.showChat(chatId: chat.id)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
+            present(alert, animated: true, completion: nil)
+        }
+    }
 }