Browse Source

Merge pull request #265 from deltachat/click_on_contact_request

Click on contact request
björn petersen 5 years ago
parent
commit
c2da2febf6

+ 8 - 3
deltachat-ios/Controller/ChatViewController.swift

@@ -428,9 +428,10 @@ class ChatViewController: MessagesViewController {
         case NSSelectorFromString("messageStartChat:"):
         case NSSelectorFromString("messageStartChat:"):
             let msg = messageList[indexPath.section]
             let msg = messageList[indexPath.section]
             logger.info("message: Start Chat \(msg.messageId)")
             logger.info("message: Start Chat \(msg.messageId)")
-            _ = msg.createChat()
+            let chat = msg.createChat()
             // TODO: figure out how to properly show the chat after creation
             // TODO: figure out how to properly show the chat after creation
             refreshMessages()
             refreshMessages()
+            coordinator?.showChat(chatId: chat.id)
         case NSSelectorFromString("messageBlock:"):
         case NSSelectorFromString("messageBlock:"):
             let msg = messageList[indexPath.section]
             let msg = messageList[indexPath.section]
             logger.info("message: Block \(msg.messageId)")
             logger.info("message: Block \(msg.messageId)")
@@ -776,7 +777,7 @@ extension ChatViewController: MessagesLayoutDelegate {
 
 
 // MARK: - MessageCellDelegate
 // MARK: - MessageCellDelegate
 extension ChatViewController: MessageCellDelegate {
 extension ChatViewController: MessageCellDelegate {
-    func didTapMessage(in cell: MessageCollectionViewCell) {
+    @objc func didTapMessage(in cell: MessageCollectionViewCell) {
         if let indexPath = messagesCollectionView.indexPath(for: cell) {
         if let indexPath = messagesCollectionView.indexPath(for: cell) {
             let message = messageList[indexPath.section]
             let message = messageList[indexPath.section]
 
 
@@ -811,7 +812,7 @@ extension ChatViewController: MessageCellDelegate {
         }
         }
     }
     }
 
 
-    func didTapAvatar(in _: MessageCollectionViewCell) {
+    @objc func didTapAvatar(in _: MessageCollectionViewCell) {
         logger.info("Avatar tapped")
         logger.info("Avatar tapped")
     }
     }
 
 
@@ -822,6 +823,10 @@ extension ChatViewController: MessageCellDelegate {
     @objc(didTapCellBottomLabelIn:) func didTapCellBottomLabel(in _: MessageCollectionViewCell) {
     @objc(didTapCellBottomLabelIn:) func didTapCellBottomLabel(in _: MessageCollectionViewCell) {
         print("Bottom label tapped")
         print("Bottom label tapped")
     }
     }
+
+    @objc func didTapBackground(in cell: MessageCollectionViewCell) {
+        print("background of message tapped")
+    }
 }
 }
 
 
 // MARK: - MessageLabelDelegate
 // MARK: - MessageLabelDelegate

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

@@ -1,4 +1,5 @@
 import UIKit
 import UIKit
+import MessageKit
 
 
 class MailboxViewController: ChatViewController {
 class MailboxViewController: ChatViewController {
 
 
@@ -24,4 +25,35 @@ class MailboxViewController: ChatViewController {
         NavBarUtils.setBigTitle(navigationController: navigationController)
         NavBarUtils.setBigTitle(navigationController: navigationController)
     }
     }
 
 
+    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)
+        }
+    }
 }
 }

+ 9 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -401,6 +401,15 @@ class ChatViewCoordinator: NSObject, Coordinator {
         // navigationController.present(nav, animated: true, completion: nil)
         // navigationController.present(nav, animated: true, completion: nil)
     }
     }
 
 
+    func showChat(chatId: Int) {
+        let chatViewController = ChatViewController(dcContext: dcContext, chatId: chatId)
+        let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
+        childCoordinators.append(coordinator)
+        chatViewController.coordinator = coordinator
+        navigationController.popToRootViewController(animated: false)
+        navigationController.pushViewController(chatViewController, animated: true)
+    }
+
     private func sendImage(_ image: UIImage) {
     private func sendImage(_ image: UIImage) {
         DispatchQueue.global().async {
         DispatchQueue.global().async {
             if let compressedImage = image.dcCompress() {
             if let compressedImage = image.dcCompress() {