NCChatFileControllerWrapper.swift 976 B

12345678910111213141516171819202122232425262728
  1. //
  2. // SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import Foundation
  6. public class NCChatFileControllerWrapper: NSObject, NCChatFileControllerDelegate {
  7. let fileController = NCChatFileController()
  8. var completionBlock: ((_ fileLocalPath: String?) -> Void)?
  9. public func downloadFile(withFileId fileId: String, completionBlock: @escaping (_ fileLocalPath: String?) -> Void) {
  10. self.completionBlock = completionBlock
  11. fileController.delegate = self
  12. fileController.downloadFile(withFileId: fileId)
  13. }
  14. public func fileControllerDidLoadFile(_ fileController: NCChatFileController, with fileStatus: NCChatFileStatus) {
  15. self.completionBlock?(fileStatus.fileLocalPath)
  16. }
  17. public func fileControllerDidFailLoadingFile(_ fileController: NCChatFileController, withErrorDescription errorDescription: String) {
  18. self.completionBlock?(nil)
  19. }
  20. }