Sfoglia il codice sorgente

Merge pull request #925 from deltachat/show-encr-info

add option to show contact-encryption-info
cyBerta 4 anni fa
parent
commit
449091fd31

+ 9 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -178,6 +178,15 @@ public class DcContext {
         return []
     }
 
+    public func getContactEncrInfo(contactId: Int) -> String {
+        if let cString = dc_get_contact_encrinfo(contextPointer, UInt32(contactId)) {
+            let switftString = String(cString: cString)
+            dc_str_unref(cString)
+            return switftString
+        }
+        return "ErrGetContactEncrInfo"
+    }
+
     public func interruptIdle() {
     }
 

+ 22 - 0
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -35,6 +35,14 @@ class ContactDetailViewController: UITableViewController {
         return cell
     }()
 
+    private lazy var showEncrInfoCell: ActionCell = {
+        let cell = ActionCell()
+        cell.actionTitle = String.localized("encryption_info_title_desktop")
+        cell.actionColor = SystemColor.blue.uiColor
+        cell.selectionStyle = .none
+        return cell
+    }()
+
     private lazy var blockContactCell: ActionCell = {
         let cell = ActionCell()
         cell.actionTitle = viewModel.contact.isBlocked ? String.localized("menu_unblock_contact") : String.localized("menu_block_contact")
@@ -163,6 +171,8 @@ class ContactDetailViewController: UITableViewController {
             switch viewModel.chatActionFor(row: row) {
             case .archiveChat:
                 return archiveChatCell
+            case .showEncrInfo:
+                return showEncrInfoCell
             case .blockContact:
                 return blockContactCell
             case .deleteChat:
@@ -228,6 +238,8 @@ class ContactDetailViewController: UITableViewController {
         switch action {
         case .archiveChat:
             toggleArchiveChat()
+        case .showEncrInfo:
+            showEncrInfoAlert()
         case .blockContact:
             toggleBlockContact()
         case .deleteChat:
@@ -292,6 +304,16 @@ class ContactDetailViewController: UITableViewController {
         self.present(alert, animated: true, completion: nil)
     }
 
+    private func showEncrInfoAlert() {
+        let alert = UIAlertController(
+            title: nil,
+            message: self.viewModel.context.getContactEncrInfo(contactId: self.viewModel.contactId),
+            preferredStyle: .alert
+        )
+        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+        self.present(alert, animated: true, completion: nil)
+    }
+
     private func showEphemeralMessagesController() {
         let ephemeralMessagesController = SettingsEphemeralMessageController(dcContext: viewModel.context, chatId: viewModel.chatId)
         navigationController?.pushViewController(ephemeralMessagesController, animated: true)

+ 3 - 2
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -21,6 +21,7 @@ class ContactDetailViewModel {
 
     enum ChatAction {
         case archiveChat
+        case showEncrInfo
         case blockContact
         case deleteChat
     }
@@ -51,10 +52,10 @@ class ContactDetailViewModel {
 
         if chatId != 0 {
             chatOptions = [.gallery, .documents, .ephemeralMessages, .muteChat, .startChat]
-            chatActions = [.archiveChat, .blockContact, .deleteChat]
+            chatActions = [.archiveChat, .showEncrInfo, .blockContact, .deleteChat]
         } else {
             chatOptions = [.gallery, .documents, .startChat]
-            chatActions = [.blockContact]
+            chatActions = [.showEncrInfo, .blockContact]
         }
     }