NCShare+NCCellDelegate.swift 3.5 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. // open share menu
  34. self.toggleShareMenu(for: tableShare)
  35. } else if isFilesSharingPublicPasswordEnforced {
  36. // create share with pw
  37. let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
  38. alertController.addTextField { textField in
  39. textField.isSecureTextEntry = true
  40. }
  41. alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { _ in })
  42. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in
  43. let password = alertController.textFields?.first?.text
  44. self.networking?.createShareLink(password: password ?? "")
  45. }
  46. alertController.addAction(okAction)
  47. self.present(alertController, animated: true, completion: nil)
  48. } else {
  49. // create sahre without pw
  50. networking?.createShareLink(password: "")
  51. }
  52. }
  53. func showProfile(with tableShare: tableShare?, sender: Any) {
  54. guard let tableShare = tableShare else { return }
  55. showProfileMenu(userId: tableShare.shareWith)
  56. }
  57. func quickStatus(with tableShare: tableShare?, sender: Any) {
  58. guard let tableShare = tableShare,
  59. let metadata = metadata,
  60. tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption else { return }
  61. let quickStatusMenu = NCShareQuickStatusMenu()
  62. quickStatusMenu.toggleMenu(viewController: self, directory: metadata.directory, tableShare: tableShare)
  63. }
  64. }