2023-01-24 11:14:50 +01:00
|
|
|
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Intents
|
|
|
|
import MastodonCore
|
|
|
|
import MastodonSDK
|
|
|
|
import MastodonLocalization
|
|
|
|
|
|
|
|
class FollowersCountIntentHandler: INExtension, FollowersCountIntentHandling {
|
2023-01-30 11:21:04 +01:00
|
|
|
func resolveShowChart(for intent: FollowersCountIntent) async -> INBooleanResolutionResult {
|
|
|
|
return .success(with: intent.showChart?.boolValue ?? false)
|
|
|
|
}
|
|
|
|
|
2023-01-24 11:14:50 +01:00
|
|
|
func resolveAccount(for intent: FollowersCountIntent) async -> INStringResolutionResult {
|
|
|
|
.confirmationRequired(with: intent.account)
|
|
|
|
}
|
|
|
|
|
|
|
|
func provideAccountOptionsCollection(for intent: FollowersCountIntent, searchTerm: String?) async throws -> INObjectCollection<NSString> {
|
|
|
|
guard
|
|
|
|
let searchTerm = searchTerm,
|
|
|
|
let authenticationBox = WidgetExtension.appContext
|
|
|
|
.authenticationService
|
|
|
|
.mastodonAuthenticationBoxes
|
|
|
|
.first
|
|
|
|
else {
|
|
|
|
return INObjectCollection(items: [])
|
|
|
|
}
|
|
|
|
|
|
|
|
let results = try await WidgetExtension.appContext
|
|
|
|
.apiService
|
|
|
|
.search(query: .init(q: searchTerm), authenticationBox: authenticationBox)
|
|
|
|
|
2023-02-07 12:36:13 +01:00
|
|
|
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomainIfMissing(authenticationBox.domain) as NSString })
|
2023-01-24 11:14:50 +01:00
|
|
|
}
|
|
|
|
}
|