NCShare+NCCellDelegate.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // NCShare+NCCellDelegate.swift
  3. // Nextcloud
  4. //
  5. // Created by Henrik Storch on 03.01.22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. import UIKit
  9. // MARK: - NCCell Delegates
  10. extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate {
  11. func copyInternalLink(sender: Any) {
  12. guard let metadata = self.metadata, let appDelegate = appDelegate else { return }
  13. let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
  14. NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, account: metadata.account) { _, metadata, errorCode, errorDescription in
  15. if errorCode == 0, let metadata = metadata {
  16. let internalLink = appDelegate.urlBase + "/index.php/f/" + metadata.fileId
  17. NCShareCommon.shared.copyLink(link: internalLink, viewController: self, sender: sender)
  18. } else {
  19. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  20. }
  21. }
  22. }
  23. func tapCopy(with tableShare: tableShare?, sender: Any) {
  24. guard let tableShare = tableShare else {
  25. return copyInternalLink(sender: sender)
  26. }
  27. NCShareCommon.shared.copyLink(link: tableShare.url, viewController: self, sender: sender)
  28. }
  29. func tapMenu(with tableShare: tableShare?, sender: Any) {
  30. guard let metadata = self.metadata else { return }
  31. let isFilesSharingPublicPasswordEnforced = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
  32. if let tableShare = tableShare {
  33. // TODO: open share menu
  34. } else if isFilesSharingPublicPasswordEnforced {
  35. // create share with pw
  36. let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
  37. alertController.addTextField { textField in
  38. textField.isSecureTextEntry = true
  39. }
  40. alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { _ in })
  41. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in
  42. let password = alertController.textFields?.first?.text
  43. self.networking?.createShareLink(password: password ?? "")
  44. }
  45. alertController.addAction(okAction)
  46. self.present(alertController, animated: true, completion: nil)
  47. } else {
  48. // create sahre without pw
  49. networking?.createShareLink(password: "")
  50. }
  51. }
  52. func showProfile(with tableShare: tableShare?, sender: Any) {
  53. guard let tableShare = tableShare else { return }
  54. showProfileMenu(userId: tableShare.shareWith)
  55. }
  56. func quickStatus(with tableShare: tableShare?, sender: Any) {
  57. guard let tableShare = tableShare,
  58. let metadata = metadata,
  59. tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption else { return }
  60. let quickStatusMenu = NCShareQuickStatusMenu()
  61. quickStatusMenu.toggleMenu(viewController: self, directory: metadata.directory, tableShare: tableShare)
  62. }
  63. }