Procházet zdrojové kódy

add more context to dialogs shown after `sendToChat()` (#1907)

* add more context to sendToChat() temp. confirmation titles (this is subject to be removed)

* add more context to forward title when started from sendToChat()
bjoern před 2 roky
rodič
revize
48c5459dc2

+ 1 - 1
deltachat-ios/Controller/ChatListController.swift

@@ -654,7 +654,7 @@ class ChatListController: UITableViewController {
         titleView.accessibilityHint = String.localized("a11y_connectivity_hint")
         if RelayHelper.shared.isForwarding() {
             // multi-select is not allowed during forwarding
-            titleView.text = RelayHelper.shared.forwardIds != nil ? String.localized("forward_to") : String.localized("chat_share_with_title")
+            titleView.text = RelayHelper.shared.dialogTitle
             if !isArchive {
                 navigationItem.setLeftBarButton(cancelButton, animated: true)
             }

+ 15 - 9
deltachat-ios/Controller/WebxdcViewController.swift

@@ -411,23 +411,29 @@ extension WebxdcViewController: WKScriptMessageHandler {
             _ = dcContext.sendWebxdcStatusUpdate(msgId: messageId, payload: payloadString, description: description)
 
         case .sendToChat:
-            let alert = UIAlertController(title: String.localized("chat_share_with_title"), message: nil, preferredStyle: .safeActionSheet)
-            alert.addAction(UIAlertAction(title: String.localized("select_chat"), style: .default, handler: { _ in
-                if let dict = message.body as? [String: AnyObject] {
+            if let dict = message.body as? [String: AnyObject] {
+                let title: String
+                if let name = dict["name"] as? String {
+                    title = String.localizedStringWithFormat(String.localized("send_file_to"), name)
+                } else {
+                    title = String.localized("send_message_to")
+                }
+
+                let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
+                alert.addAction(UIAlertAction(title: String.localized("select_chat"), style: .default, handler: { _ in
                     let base64 = dict["base64"] as? String
                     let data = base64 != nil ? Data(base64Encoded: base64 ?? "") : nil
-                    RelayHelper.shared.setForwardMessage(text: dict["text"] as? String, fileData: data, fileName: dict["name"] as? String)
+                    RelayHelper.shared.setForwardMessage(dialogTitle: title, text: dict["text"] as? String, fileData: data, fileName: dict["name"] as? String)
 
                     if let appDelegate = UIApplication.shared.delegate as? AppDelegate,
                        let rootController = appDelegate.appCoordinator.tabBarController.selectedViewController as? UINavigationController {
                         appDelegate.appCoordinator.showTab(index: appDelegate.appCoordinator.chatsTab)
                         rootController.popToRootViewController(animated: false)
                     }
-                }
-            }))
-            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-            self.present(alert, animated: true, completion: nil)
-
+                }))
+                alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+                self.present(alert, animated: true, completion: nil)
+            }
 
         default:
             logger.debug("another method was called")

+ 7 - 1
deltachat-ios/Helper/RelayHelper.swift

@@ -5,6 +5,8 @@ class RelayHelper {
     static var shared: RelayHelper = RelayHelper()
     private static var dcContext: DcContext?
 
+    var dialogTitle: String = ""
+
     var forwardIds: [Int]?
     var forwardText: String?
     var forwardFileData: Data?
@@ -28,8 +30,9 @@ class RelayHelper {
 
     // forwarding messages
 
-    func setForwardMessage(text: String?, fileData: Data?, fileName: String?) {
+    func setForwardMessage(dialogTitle: String, text: String?, fileData: Data?, fileName: String?) {
         finishRelaying()
+        self.dialogTitle = dialogTitle
         self.forwardText = text
         self.forwardFileData = fileData
         self.forwardFileName = fileName
@@ -37,11 +40,13 @@ class RelayHelper {
 
     func setForwardMessage(messageId: Int) {
         finishRelaying()
+        self.dialogTitle = String.localized("forward_to")
         self.forwardIds = [messageId]
     }
 
     func setForwardMessages(messageIds: [Int]) {
         finishRelaying()
+        self.dialogTitle = String.localized("forward_to")
         if !messageIds.isEmpty {
             self.forwardIds = messageIds
         }
@@ -59,6 +64,7 @@ class RelayHelper {
     }
 
     func finishRelaying() {
+        dialogTitle = ""
         forwardIds = nil
         forwardText = nil
         forwardFileData = nil