Pārlūkot izejas kodu

adapt to new decicition-api

B. Petersen 4 gadi atpakaļ
vecāks
revīzija
27090b4537

+ 7 - 6
DcCore/DcCore/DC/Wrapper.swift

@@ -85,8 +85,9 @@ public class DcContext {
         }
     }
 
-    public func createChatByMessageId(_ messageId: Int) -> DcChat {
-        let chatId = dc_create_chat_by_msg_id(contextPointer, UInt32(messageId))
+    @discardableResult
+    public func decideOnContactRequest(_ messageId: Int, _ decision: Int32) -> DcChat {
+        let chatId = dc_decide_on_contact_request(contextPointer, UInt32(messageId), decision)
         return getChat(chatId: Int(chatId))
     }
 
@@ -832,6 +833,10 @@ public class DcMsg {
         return Int(dc_msg_get_chat_id(messagePointer))
     }
 
+    public var realChatId: Int {
+        return Int(dc_msg_get_real_chat_id(messagePointer))
+    }
+
     public var text: String? {
         set {
             if let newValue = newValue {
@@ -1147,10 +1152,6 @@ public class DcContact {
     public func unblock() {
         dc_block_contact(DcContext.shared.contextPointer, UInt32(id), 0)
     }
-
-    public func marknoticed() {
-        dc_marknoticed_contact(DcContext.shared.contextPointer, UInt32(id))
-    }
 }
 
 public class DcLot {

+ 6 - 7
deltachat-ios/Controller/ChatListController.swift

@@ -337,21 +337,20 @@ class ChatListController: UITableViewController {
 
     private func showDeaddropRequestAlert(msgId: Int) {
         let dcMsg = DcMsg(id: msgId)
-        let dcContact = DcContact(id: dcMsg.fromContactId)
-        let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
+        let (title, startButton, blockButton) = MailboxViewController.deaddropQuestion(context: dcContext, msg: dcMsg)
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-            let chat = self.dcContext.createChatByMessageId(msgId)
+        alert.addAction(UIAlertAction(title: startButton, style: .default, handler: { _ in
+            let chat = self.dcContext.decideOnContactRequest(msgId, DC_DECISION_START_CHAT)
             self.showChat(chatId: chat.id)
         }))
         alert.addAction(UIAlertAction(title: String.localized("not_now"), style: .default, handler: { _ in
             DispatchQueue.global(qos: .background).async {
-                dcContact.marknoticed()
+                self.dcContext.decideOnContactRequest(msgId, DC_DECISION_NOT_NOW)
             }
         }))
-        alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
+        alert.addAction(UIAlertAction(title: blockButton, style: .destructive, handler: { _ in
             DispatchQueue.global(qos: .background).async {
-                dcContact.block()
+                self.dcContext.decideOnContactRequest(msgId, DC_DECISION_BLOCK)
             }
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))

+ 18 - 6
deltachat-ios/Controller/MailboxViewController.swift

@@ -36,6 +36,19 @@ class MailboxViewController: ChatViewController {
         askToChat(messageId: messageIds[indexPath.row])
     }
 
+    // function builds the correct question when tapping on a deaddrop message.
+    // returns a tuple (question, startButton, blockButton)
+    public static func deaddropQuestion(context: DcContext, msg: DcMsg) -> (String, String, String) {
+        let chat = context.getChat(chatId: msg.realChatId)
+        if chat.isMailinglist {
+            let question = String.localizedStringWithFormat(String.localized("ask_show_mailing_list"), chat.name)
+            return (question, String.localized("yes"), String.localized("block"))
+        } else {
+            let contact = msg.fromContact
+            let question = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), contact.nameNAddr)
+            return (question, String.localized("start_chat"), String.localized("menu_block_contact"))
+        }
+    }
 
     func askToChat(messageId: Int) {
         if handleUIMenu() { return }
@@ -43,15 +56,14 @@ class MailboxViewController: ChatViewController {
         if message.isInfo {
             return
         }
-        let dcContact = message.fromContact
-        let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
+        let (title, startButton, blockButton) = MailboxViewController.deaddropQuestion(context: dcContext, msg: message)
         let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-            let chat = self.dcContext.createChatByMessageId(messageId)
+        alert.addAction(UIAlertAction(title: startButton, style: .default, handler: { _ in
+            let chat = self.dcContext.decideOnContactRequest(messageId, DC_DECISION_START_CHAT)
             self.showChat(chatId: chat.id)
         }))
-        alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
-            dcContact.block()
+        alert.addAction(UIAlertAction(title: blockButton, style: .destructive, handler: { _ in
+            self.dcContext.decideOnContactRequest(messageId, DC_DECISION_BLOCK)
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel))
         present(alert, animated: true, completion: nil)