Explorar el Código

Merge pull request #299 from deltachat/on_chatlist_avatar_tapped

On chatlist avatar tapped
björn petersen hace 5 años
padre
commit
fc92efb581

+ 11 - 11
deltachat-ios/Controller/ChatViewController.swift

@@ -546,17 +546,13 @@ extension ChatViewController: MessagesDataSource {
             return false
         }
 
-        if let _ = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian) {
-            let dateA = messageA.sentDate
-            let dateB = messageB.sentDate
-
-            let timeinterval = dateB.timeIntervalSince(dateA)
-            let minute = 60.0
+        let dateA = messageA.sentDate
+        let dateB = messageB.sentDate
 
-            return messageA.fromContactId == messageB.fromContactId && timeinterval.isLessThanOrEqualTo(minute)
-        }
+        let timeinterval = dateB.timeIntervalSince(dateA)
+        let minute = 60.0
 
-        return false
+        return messageA.fromContactId == messageB.fromContactId && timeinterval.isLessThanOrEqualTo(minute)
 
     }
 
@@ -878,8 +874,12 @@ extension ChatViewController: MessageCellDelegate {
         navigationController?.present(inputDlg, animated: true, completion: nil)
     }
 
-    @objc func didTapAvatar(in _: MessageCollectionViewCell) {
-        logger.info("Avatar tapped")
+    @objc func didTapAvatar(in cell: MessageCollectionViewCell) {
+        if let indexPath = messagesCollectionView.indexPath(for: cell) {
+            let message = messageList[indexPath.section]
+            let chat = DcChat(id: chatId)
+            coordinator?.showContactDetail(of: message.fromContact.id, in: chat.chatType)
+        }
     }
 
     @objc(didTapCellTopLabelIn:) func didTapCellTopLabel(in _: MessageCollectionViewCell) {

+ 14 - 5
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -3,6 +3,11 @@ import UIKit
 // this is also used as ChatDetail for SingleChats
 class ContactDetailViewController: UITableViewController {
     weak var coordinator: ContactDetailCoordinatorProtocol?
+    let sectionOptions = 0
+    let sectionBlockContact = 1
+    let sectionOptionsRowNotifications = 0
+    var showStartChat = true
+    var optionCells: [UITableViewCell] = []
 
     private enum CellIdentifiers: String {
         case notification = "notificationCell"
@@ -59,6 +64,10 @@ class ContactDetailViewController: UITableViewController {
             title: String.localized("global_menu_edit_desktop"),
             style: .plain, target: self, action: #selector(editButtonPressed))
         self.title = String.localized("tab_contact")
+        optionCells.insert(notificationsCell, at: 0)
+        if showStartChat {
+            optionCells.insert(chatCell, at: 1)
+        }
     }
 
     override func viewWillAppear(_ animated: Bool) {
@@ -71,9 +80,9 @@ class ContactDetailViewController: UITableViewController {
     }
 
     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        if section == 0 {
-            return 2
-        } else if section == 1 {
+        if section == sectionOptions {
+            return optionCells.count
+        } else if section == sectionBlockContact {
             return 1
         }
         return 0
@@ -83,8 +92,8 @@ class ContactDetailViewController: UITableViewController {
         let section = indexPath.section
         let row = indexPath.row
 
-        if section == 0 {
-            if row == 0 {
+        if section == sectionOptions {
+            if row == sectionOptionsRowNotifications {
                 return notificationsCell
             } else {
                 return chatCell

+ 5 - 3
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -376,6 +376,7 @@ class ChatViewCoordinator: NSObject, Coordinator {
         case .SINGLE:
             if let contactId = chat.contactIds.first {
                 let contactDetailController = ContactDetailViewController(contactId: contactId)
+                contactDetailController.showStartChat = false
                 let coordinator = ContactDetailCoordinator(dcContext: dcContext, navigationController: navigationController)
                 childCoordinators.append(coordinator)
                 contactDetailController.coordinator = coordinator
@@ -390,14 +391,15 @@ class ChatViewCoordinator: NSObject, Coordinator {
         }
     }
 
-    func showContactDetail(of contactId: Int) {
+    func showContactDetail(of contactId: Int, in chatOfType: ChatType) {
         let contactDetailController = ContactDetailViewController(contactId: contactId)
-        //let nav = UINavigationController(rootViewController: contactDetailController)
+        if chatOfType == .SINGLE {
+            contactDetailController.showStartChat = false
+        }
         let coordinator = ContactDetailCoordinator(dcContext: dcContext, navigationController: navigationController)
         childCoordinators.append(coordinator)
         contactDetailController.coordinator = coordinator
         navigationController.pushViewController(contactDetailController, animated: true)
-        // navigationController.present(nav, animated: true, completion: nil)
     }
 
     func showChat(chatId: Int) {