瀏覽代碼

Merge pull request #303 from deltachat/on_avatar_tapped_in_group_details

open contact details on tap on group member's avatar (#82)
björn petersen 5 年之前
父節點
當前提交
e509df9b26

+ 11 - 4
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -210,6 +210,9 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
                 coordinator?.showAddGroupMember(chatId: chat.id)
             } else if row == sectionMembersRowJoinQR {
                 coordinator?.showQrCodeInvite(chatId: chat.id)
+            } else {
+                let contact = getGroupMember(at: row)
+                coordinator?.showContactDetail(of: contact.id)
             }
             // ignore for now - in Telegram tapping a contactCell leads into ContactDetail
         } else if section == sectionLeaveGroup {
@@ -237,13 +240,11 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         if section == sectionMembers, row >= staticCellCountMemberSection, groupMembers[row - staticCellCountMemberSection].id != currentUser?.id {
             let delete = UITableViewRowAction(style: .destructive, title: String.localized("remove_desktop")) { [unowned self] _, indexPath in
 
-                let memberId = self.groupMembers[row - self.staticCellCountMemberSection].id
-                let contact = DcContact(id: memberId)
-
+                let contact = self.getGroupMember(at: row)
                 let title = String.localizedStringWithFormat(String.localized("ask_remove_members"), contact.nameNAddr)
                 let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
                 alert.addAction(UIAlertAction(title: String.localized("remove_desktop"), style: .destructive, handler: { _ in
-                    let success = dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(memberId))
+                    let success = dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(contact.id))
                     if success == 1 {
                         self.groupMembers.remove(at: row - self.staticCellCountMemberSection)
                         tableView.deleteRows(at: [indexPath], with: .fade)
@@ -259,4 +260,10 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             return nil
         }
     }
+
+    func getGroupMember(at row: Int) -> DcContact {
+        let memberId = self.groupMembers[row - self.staticCellCountMemberSection].id
+        return DcContact(id: memberId)
+    }
+
 }

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

@@ -354,6 +354,14 @@ class GroupChatDetailCoordinator: Coordinator {
         editGroupViewController.coordinator = coordinator
         navigationController.pushViewController(editGroupViewController, animated: true)
     }
+
+    func showContactDetail(of contactId: Int) {
+        let contactDetailController = ContactDetailViewController(contactId: contactId)
+        let coordinator = ContactDetailCoordinator(dcContext: dcContext, navigationController: navigationController)
+        childCoordinators.append(coordinator)
+        contactDetailController.coordinator = coordinator
+        navigationController.pushViewController(contactDetailController, animated: true)
+    }
 }
 
 class ChatViewCoordinator: NSObject, Coordinator {

+ 21 - 0
deltachat-ios/View/ContactCell.swift

@@ -13,8 +13,14 @@ enum MessageDeliveryState: Int {
     case OUTMDNRCVD = 28
 }
 
+protocol ContactCellDelegate: class {
+    func onAvatarTapped(at index: Int)
+}
+
 class ContactCell: UITableViewCell {
 
+    weak var delegate: ContactCellDelegate?
+    var rowIndex = -1
     private let initialsLabelSize: CGFloat = 54
     private let imgSize: CGFloat = 25
 
@@ -158,6 +164,12 @@ class ContactCell: UITableViewCell {
 
         imgView.center.x = avatar.center.x + (avatar.frame.width / 2) + imgSize - 5
         imgView.center.y = avatar.center.y + (avatar.frame.height / 2) + imgSize - 5
+
+        if delegate != nil {
+            let tap = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
+            avatar.addGestureRecognizer(tap)
+        }
+
     }
 
     func setVerified(isVerified: Bool) {
@@ -231,6 +243,15 @@ class ContactCell: UITableViewCell {
         initialsLabel.backgroundColor = color
     }
 
+    @objc func onAvatarTapped() {
+        if let delegate = delegate {
+            if rowIndex == -1 {
+                return
+            }
+            delegate.onAvatarTapped(at: rowIndex)
+        }
+    }
+
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }