From e52fb6ea32d21869b4085ca9b913fe8c719339e9 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 18 Oct 2019 20:06:18 -0500 Subject: [PATCH] Make account selectable --- iOS/Intents/AddFeedIntentHandler.swift | 19 ++++- iOS/Intents/Intents.intentdefinition | 97 +++++++++++++++++++++----- 2 files changed, 97 insertions(+), 19 deletions(-) diff --git a/iOS/Intents/AddFeedIntentHandler.swift b/iOS/Intents/AddFeedIntentHandler.swift index 7868743a4..d648b6eb1 100644 --- a/iOS/Intents/AddFeedIntentHandler.swift +++ b/iOS/Intents/AddFeedIntentHandler.swift @@ -26,14 +26,29 @@ public class AddFeedIntentHandler: NSObject, AddFeedIntentHandling { completion(.success(with: url)) } + public func provideAccountNameOptions(for intent: AddFeedIntent, with completion: @escaping ([String]?, Error?) -> Void) { + DispatchQueue.main.async { + let accountNames = AccountManager.shared.activeAccounts.compactMap { $0.nameForDisplay } + completion(accountNames, nil) + } + } + + public func resolveAccountName(for intent: AddFeedIntent, with completion: @escaping (AddFeedAccountNameResolutionResult) -> Void) { + guard let accountName = intent.accountName else { + completion(.unsupported(forReason: .required)) + return + } + completion(.success(with: accountName)) + } + public func handle(intent: AddFeedIntent, completion: @escaping (AddFeedIntentResponse) -> Void) { - guard let url = intent.url else { + guard let url = intent.url, let accountName = intent.accountName else { completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) return } DispatchQueue.main.async { - guard let account = AccountManager.shared.activeAccounts.first else { + guard let account = AccountManager.shared.activeAccounts.first(where: { $0.nameForDisplay == accountName }) else { completion(AddFeedIntentResponse(code: .failure, userActivity: nil)) return } diff --git a/iOS/Intents/Intents.intentdefinition b/iOS/Intents/Intents.intentdefinition index a6efc699b..7a1bc85af 100644 --- a/iOS/Intents/Intents.intentdefinition +++ b/iOS/Intents/Intents.intentdefinition @@ -25,20 +25,22 @@ Add a feed INIntentDescriptionID IuAbef + INIntentIneligibleForSuggestions + INIntentInput url INIntentKeyParameter url INIntentLastParameterTag - 2 + 3 INIntentManagedParameterCombinations - url + url,accountName INIntentParameterCombinationSupportsBackgroundExecution INIntentParameterCombinationTitle - ${url} + Add${url}to ${accountName} INIntentParameterCombinationTitleID dkSFD2 INIntentParameterCombinationUpdatesLinked @@ -47,20 +49,6 @@ INIntentName AddFeed - INIntentParameterCombinations - - url - - INIntentParameterCombinationIsLinked - - INIntentParameterCombinationSupportsBackgroundExecution - - INIntentParameterCombinationTitle - ${url} - INIntentParameterCombinationTitleID - Nx8zSj - - INIntentParameters @@ -105,6 +93,81 @@ + + INIntentParameterCustomDisambiguation + + INIntentParameterDisplayName + Account Name + INIntentParameterDisplayNameID + CSrgUY + INIntentParameterDisplayPriority + 2 + INIntentParameterMetadata + + INIntentParameterMetadataCapitalization + Sentences + + INIntentParameterName + accountName + INIntentParameterPromptDialogs + + + INIntentParameterPromptDialogCustom + + INIntentParameterPromptDialogType + Primary + + + INIntentParameterPromptDialogCustom + + INIntentParameterPromptDialogFormatString + There are ${count} options matching ‘${accountName}’. + INIntentParameterPromptDialogFormatStringID + IbqUVS + INIntentParameterPromptDialogType + DisambiguationIntroduction + + + INIntentParameterPromptDialogFormatString + Which one? + INIntentParameterPromptDialogFormatStringID + fWs3li + INIntentParameterPromptDialogType + DisambiguationSelection + + + INIntentParameterPromptDialogCustom + + INIntentParameterPromptDialogFormatString + Just to confirm, you wanted ‘${accountName}’? + INIntentParameterPromptDialogFormatStringID + HHiZUh + INIntentParameterPromptDialogType + Confirmation + + + INIntentParameterSupportsDynamicEnumeration + + INIntentParameterSupportsResolution + + INIntentParameterTag + 3 + INIntentParameterType + String + INIntentParameterUnsupportedReasons + + + INIntentParameterUnsupportedReasonCode + required + INIntentParameterUnsupportedReasonCustom + + INIntentParameterUnsupportedReasonFormatString + An account name is required. + INIntentParameterUnsupportedReasonFormatStringID + JGkCuS + + + INIntentResponse