瀏覽代碼

show webxdc-selector and -profile-tabs only if there are webxdc (#1706)

bjoern 2 年之前
父節點
當前提交
43b692d2da

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

@@ -272,6 +272,10 @@ public class DcContext {
         return messageIds
     }
 
+    public func hasWebxdc(chatId: Int) -> Bool {
+        return !getChatMedia(chatId: chatId, messageType: DC_MSG_WEBXDC, messageType2: 0, messageType3: 0).isEmpty
+    }
+
     @discardableResult
     public func createChatByContactId(contactId: Int) -> Int {
         return Int(dc_create_chat_by_contact_id(contextPointer, UInt32(contactId)))

+ 6 - 2
deltachat-ios/Chat/ChatViewController.swift

@@ -1350,7 +1350,6 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
         let galleryAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
         let cameraAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
         let documentAction = UIAlertAction(title: String.localized("files"), style: .default, handler: documentActionPressed(_:))
-        let webxdcAction = UIAlertAction(title: String.localized("webxdc_apps"), style: .default, handler: webxdcButtonPressed(_:))
         let voiceMessageAction = UIAlertAction(title: String.localized("voice_message"), style: .default, handler: voiceMessageButtonPressed(_:))
         let isLocationStreaming = dcContext.isSendingLocationsToChat(chatId: chatId)
         let locationStreamingAction = UIAlertAction(title: isLocationStreaming ? String.localized("stop_sharing_location") : String.localized("location"),
@@ -1360,7 +1359,12 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
         alert.addAction(cameraAction)
         alert.addAction(galleryAction)
         alert.addAction(documentAction)
-        alert.addAction(webxdcAction)
+
+        if dcContext.hasWebxdc(chatId: 0) {
+            let webxdcAction = UIAlertAction(title: String.localized("webxdc_apps"), style: .default, handler: webxdcButtonPressed(_:))
+            alert.addAction(webxdcAction)
+        }
+        
         alert.addAction(voiceMessageAction)
 
         if let config = dcContext.getConfig("webrtc_instance"), !config.isEmpty {

+ 2 - 2
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -79,7 +79,7 @@ class ContactDetailViewController: UITableViewController {
 
     private lazy var documentsCell: UITableViewCell = {
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
-        cell.textLabel?.text = String.localized("files_and_webxdx_apps")
+        cell.textLabel?.text = String.localized(viewModel.hasWebxdc ? "files_and_webxdx_apps" : "files")
         cell.accessoryType = .disclosureIndicator
         if viewModel.chatId == 0 {
             cell.isUserInteractionEnabled = false
@@ -470,7 +470,7 @@ class ContactDetailViewController: UITableViewController {
 
     private func showDocuments() {
         let messageIds: [Int] = viewModel.documentItemMessageIds.reversed()
-        let fileGalleryController = DocumentGalleryController(context: viewModel.context, chatId: viewModel.chatId, fileMessageIds: messageIds)
+        let fileGalleryController = DocumentGalleryController(context: viewModel.context, chatId: viewModel.chatId, fileMessageIds: messageIds, hasWebxdc: viewModel.hasWebxdc)
         navigationController?.pushViewController(fileGalleryController, animated: true)
     }
 

+ 2 - 2
deltachat-ios/Controller/DocumentGalleryController.swift

@@ -55,12 +55,12 @@ class DocumentGalleryController: UIViewController {
         return menu
     }()
 
-    init(context: DcContext, chatId: Int, fileMessageIds: [Int]) {
+    init(context: DcContext, chatId: Int, fileMessageIds: [Int], hasWebxdc: Bool) {
         self.dcContext = context
         self.fileMessageIds = fileMessageIds
         self.chatId = chatId
         super.init(nibName: nil, bundle: nil)
-        self.title = String.localized("files_and_webxdx_apps")
+        self.title = String.localized(hasWebxdc ? "files_and_webxdx_apps" : "files")
     }
 
     required init?(coder: NSCoder) {

+ 6 - 2
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -61,6 +61,10 @@ class GroupChatDetailViewController: UIViewController {
         )
     }
 
+    private lazy var hasWebxdc: Bool = {
+        return dcContext.hasWebxdc(chatId: chatId)
+    }()
+
     // stores contactIds
     private var groupMemberIds: [Int] = []
     
@@ -134,7 +138,7 @@ class GroupChatDetailViewController: UIViewController {
 
     private lazy var documentsCell: UITableViewCell = {
         let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
-        cell.textLabel?.text = String.localized("files_and_webxdx_apps")
+        cell.textLabel?.text = String.localized(hasWebxdc ? "files_and_webxdx_apps" : "files")
         cell.accessoryType = .disclosureIndicator
         return cell
     }()
@@ -422,7 +426,7 @@ class GroupChatDetailViewController: UIViewController {
 
     private func showDocuments() {
         let messageIds: [Int] = documentItemMessageIds.reversed()
-        let fileGalleryController = DocumentGalleryController(context: dcContext, chatId: chatId, fileMessageIds: messageIds)
+        let fileGalleryController = DocumentGalleryController(context: dcContext, chatId: chatId, fileMessageIds: messageIds, hasWebxdc: hasWebxdc)
         navigationController?.pushViewController(fileGalleryController, animated: true)    }
 
     private func showGallery() {

+ 4 - 0
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -135,6 +135,10 @@ class ContactDetailViewModel {
         )
     }
 
+    lazy var hasWebxdc: Bool = {
+        return context.hasWebxdc(chatId: chatId)
+    }()
+
     var numberOfSections: Int {
         return sections.count
     }