Explorar o código

Merge pull request #767 from deltachat/share_error_modal

show share error view if account was not configured yet
cyBerta %!s(int64=5) %!d(string=hai) anos
pai
achega
ce5dbc5ac9

+ 23 - 13
DcShare/Controller/ShareViewController.swift

@@ -34,6 +34,7 @@ class ShareViewController: SLComposeServiceViewController {
     var selectedChat: DcChat?
     let dbHelper = DatabaseHelper()
     var shareAttachment: ShareAttachment?
+    var isAccountConfigured: Bool = true
 
     lazy var preview: UIImageView? = {
         let imageView = UIImageView(frame: .zero)
@@ -65,11 +66,15 @@ class ShareViewController: SLComposeServiceViewController {
         if dbHelper.currentDatabaseLocation == dbHelper.sharedDbFile {
             dcContext.logger = self.logger
             dcContext.openDatabase(dbFile: dbHelper.sharedDbFile)
-            selectedChatId = dcContext.getChatIdByContactId(contactId: Int(DC_CONTACT_ID_SELF))
-            if let chatId = selectedChatId {
-                selectedChat = dcContext.getChat(chatId: chatId)
+            isAccountConfigured = dcContext.isConfigured()
+            if isAccountConfigured {
+                selectedChatId = dcContext.getChatIdByContactId(contactId: Int(DC_CONTACT_ID_SELF))
+                if let chatId = selectedChatId {
+                    selectedChat = dcContext.getChat(chatId: chatId)
+                }
             }
             reloadConfigurationItems()
+            validateContent()
         } else {
             cancel()
         }
@@ -81,7 +86,7 @@ class ShareViewController: SLComposeServiceViewController {
 
     override func isContentValid() -> Bool {
         // Do validation of contentText and/or NSExtensionContext attachments here
-        return  !(contentText?.isEmpty ?? true) || !(self.shareAttachment?.isEmpty ?? true)
+        return  isAccountConfigured && (!(contentText?.isEmpty ?? true) || !(self.shareAttachment?.isEmpty ?? true))
     }
 
     private func setupNavigationBar() {
@@ -124,16 +129,21 @@ class ShareViewController: SLComposeServiceViewController {
     }
 
     override func configurationItems() -> [Any]! {
-        logger.debug("configurationItems")
-        // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
-
         let item = SLComposeSheetConfigurationItem()
-        item?.title = String.localized("forward_to")
-        item?.value = selectedChat?.name
-        logger.debug("configurationItems chat name: \(String(describing: selectedChat?.name))")
-        item?.tapHandler = {
-            let chatListController = ChatListController(dcContext: self.dcContext, chatListDelegate: self)
-            self.pushConfigurationViewController(chatListController)
+        if isAccountConfigured {
+            logger.debug("configurationItems")
+            // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
+
+
+            item?.title = String.localized("forward_to")
+            item?.value = selectedChat?.name
+            logger.debug("configurationItems chat name: \(String(describing: selectedChat?.name))")
+            item?.tapHandler = {
+                let chatListController = ChatListController(dcContext: self.dcContext, chatListDelegate: self)
+                self.pushConfigurationViewController(chatListController)
+            }
+        } else {
+            item?.title = String.localized("share_account_not_configured")
         }
 
         return [item as Any]

+ 1 - 0
deltachat-ios/en.lproj/Localizable.strings

@@ -652,3 +652,4 @@
 "stop_sharing_location" = "Stop sharing location";
 "a11y_voice_message_hint_ios" = "After recording double-tap to send. To discard the recording scrub left-right with two fingers.";
 "login_error_no_internet_connection" = "No internet connection, can\'t log in to your server.";
+"share_account_not_configured" = "Account is not configured.";

+ 2 - 0
tools/untranslated.xml

@@ -7,4 +7,6 @@
     <string name="stop_sharing_location">Stop sharing location</string>
     <string name="a11y_voice_message_hint_ios">After recording double-tap to send. To discard the recording scrub left-right with two fingers.</string>
     <string name="login_error_no_internet_connection">No internet connection, can\'t log in to your server.</string>
+    <string name="share_account_not_configured">Account is not configured.</string>
+
 </resources>