diff --git a/iOS/Intents/AddFeedIntentHandler.swift b/iOS/Intents/AddFeedIntentHandler.swift index ccf28cbd4..8e391036f 100644 --- a/iOS/Intents/AddFeedIntentHandler.swift +++ b/iOS/Intents/AddFeedIntentHandler.swift @@ -21,123 +21,123 @@ public enum AddFeedIntentHandlerError: LocalizedError { } -public class AddFeedIntentHandler: NSObject, AddFeedIntentHandling { - - override init() { - super.init() - } - - public func resolveUrl(for intent: AddFeedIntent, with completion: @escaping (AddFeedUrlResolutionResult) -> Void) { - guard let url = intent.url else { - completion(.unsupported(forReason: .required)) - return - } - completion(.success(with: url)) - } - - public func provideAccountNameOptions(for intent: AddFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) { - guard let extensionContainers = ExtensionContainersFile.read() else { - completion(nil, AddFeedIntentHandlerError.communicationFailure) - return - } - - let accountNames = extensionContainers.accounts.map { $0.name } - completion(accountNames, nil) - } - - public func resolveAccountName(for intent: AddFeedIntent, with completion: @escaping (AddFeedAccountNameResolutionResult) -> Void) { - guard let accountName = intent.accountName else { - completion(AddFeedAccountNameResolutionResult.notRequired()) - return - } - - guard let extensionContainers = ExtensionContainersFile.read() else { - completion(.unsupported(forReason: .communication)) - return - } - - if extensionContainers.findAccount(forName: accountName) == nil { - completion(.unsupported(forReason: .invalid)) - } else { - completion(.success(with: accountName)) - } - } - - public func provideFolderNameOptions(for intent: AddFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) { - guard let extensionContainers = ExtensionContainersFile.read() else { - completion(nil, AddFeedIntentHandlerError.communicationFailure) - return - } - - guard let accountName = intent.accountName, let account = extensionContainers.findAccount(forName: accountName) else { - completion([String](), nil) - return - } - - let folderNames = account.folders.map { $0.name } - completion(folderNames, nil) - } - - public func resolveFolderName(for intent: AddFeedIntent, with completion: @escaping (AddFeedFolderNameResolutionResult) -> Void) { - guard let accountName = intent.accountName, let folderName = intent.folderName else { - completion(AddFeedFolderNameResolutionResult.notRequired()) - return - } - - guard let extensionContainers = ExtensionContainersFile.read() else { - completion(.unsupported(forReason: .communication)) - return - } - - guard let account = extensionContainers.findAccount(forName: accountName) else { - completion(.unsupported(forReason: .invalid)) - return - } - - if account.findFolder(forName: folderName) == nil { - completion(.unsupported(forReason: .invalid)) - } else { - completion(.success(with: folderName)) - } - return - - } - - public func handle(intent: AddFeedIntent, completion: @escaping (AddFeedIntentResponse) -> Void) { - guard let url = intent.url, let extensionContainers = ExtensionContainersFile.read() else { - completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) - return - } - - let account: ExtensionAccount? = { - if let accountName = intent.accountName { - return extensionContainers.findAccount(forName: accountName) - } else { - return extensionContainers.accounts.first - } - }() - - guard let validAccount = account else { - completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) - return - } - - let container: ExtensionContainer? = { - if let folderName = intent.folderName { - return validAccount.findFolder(forName: folderName) - } else { - return validAccount - } - }() - - guard let validContainer = container, let containerID = validContainer.containerID else { - completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) - return - } - - let request = ExtensionFeedAddRequest(name: nil, feedURL: url, destinationContainerID: containerID) - ExtensionFeedAddRequestFile.save(request) - completion(AddFeedIntentResponse(code: .success, userActivity: nil)) - } - -} +//public class AddFeedIntentHandler: NSObject, AddFeedIntentHandling { +// +// override init() { +// super.init() +// } +// +// public func resolveUrl(for intent: AddFeedIntent, with completion: @escaping (AddFeedUrlResolutionResult) -> Void) { +// guard let url = intent.url else { +// completion(.unsupported(forReason: .required)) +// return +// } +// completion(.success(with: url)) +// } +// +// public func provideAccountNameOptions(for intent: AddFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) { +// guard let extensionContainers = ExtensionContainersFile.read() else { +// completion(nil, AddFeedIntentHandlerError.communicationFailure) +// return +// } +// +// let accountNames = extensionContainers.accounts.map { $0.name } +// completion(accountNames, nil) +// } +// +// public func resolveAccountName(for intent: AddFeedIntent, with completion: @escaping (AddFeedAccountNameResolutionResult) -> Void) { +// guard let accountName = intent.accountName else { +// completion(AddFeedAccountNameResolutionResult.notRequired()) +// return +// } +// +// guard let extensionContainers = ExtensionContainersFile.read() else { +// completion(.unsupported(forReason: .communication)) +// return +// } +// +// if extensionContainers.findAccount(forName: accountName) == nil { +// completion(.unsupported(forReason: .invalid)) +// } else { +// completion(.success(with: accountName)) +// } +// } +// +// public func provideFolderNameOptions(for intent: AddFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) { +// guard let extensionContainers = ExtensionContainersFile.read() else { +// completion(nil, AddFeedIntentHandlerError.communicationFailure) +// return +// } +// +// guard let accountName = intent.accountName, let account = extensionContainers.findAccount(forName: accountName) else { +// completion([String](), nil) +// return +// } +// +// let folderNames = account.folders.map { $0.name } +// completion(folderNames, nil) +// } +// +// public func resolveFolderName(for intent: AddFeedIntent, with completion: @escaping (AddFeedFolderNameResolutionResult) -> Void) { +// guard let accountName = intent.accountName, let folderName = intent.folderName else { +// completion(AddFeedFolderNameResolutionResult.notRequired()) +// return +// } +// +// guard let extensionContainers = ExtensionContainersFile.read() else { +// completion(.unsupported(forReason: .communication)) +// return +// } +// +// guard let account = extensionContainers.findAccount(forName: accountName) else { +// completion(.unsupported(forReason: .invalid)) +// return +// } +// +// if account.findFolder(forName: folderName) == nil { +// completion(.unsupported(forReason: .invalid)) +// } else { +// completion(.success(with: folderName)) +// } +// return +// +// } +// +// public func handle(intent: AddFeedIntent, completion: @escaping (AddFeedIntentResponse) -> Void) { +// guard let url = intent.url, let extensionContainers = ExtensionContainersFile.read() else { +// completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) +// return +// } +// +// let account: ExtensionAccount? = { +// if let accountName = intent.accountName { +// return extensionContainers.findAccount(forName: accountName) +// } else { +// return extensionContainers.accounts.first +// } +// }() +// +// guard let validAccount = account else { +// completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) +// return +// } +// +// let container: ExtensionContainer? = { +// if let folderName = intent.folderName { +// return validAccount.findFolder(forName: folderName) +// } else { +// return validAccount +// } +// }() +// +// guard let validContainer = container, let containerID = validContainer.containerID else { +// completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) +// return +// } +// +// let request = ExtensionFeedAddRequest(name: nil, feedURL: url, destinationContainerID: containerID) +// ExtensionFeedAddRequestFile.save(request) +// completion(AddFeedIntentResponse(code: .success, userActivity: nil)) +// } +// +//} diff --git a/iOS/IntentsExtension/IntentHandler.swift b/iOS/IntentsExtension/IntentHandler.swift index e3e1490a8..12b0ad1e6 100644 --- a/iOS/IntentsExtension/IntentHandler.swift +++ b/iOS/IntentsExtension/IntentHandler.swift @@ -12,8 +12,8 @@ class IntentHandler: INExtension { override func handler(for intent: INIntent) -> Any { switch intent { - case is AddFeedIntent: - return AddFeedIntentHandler() +// case is AddFeedIntent: +// return AddFeedIntentHandler() default: fatalError("Unhandled intent type: \(intent)") }