mastodon-app-ufficiale-ipho.../MastodonIntent/Handler/MultiFollowersCountIntentHandler.swift
shannon 54d04aed4e Continue to make MastodonAuthenticationBox the standard form of passing user information
Further simplify the AuthenticationViewModel and the public interface of AuthenticationServiceProvider.

Publish currentActiveUser from AuthenticationServiceProvider instead of assuming all callers know to take the first in the list as the active one.

contributes to iOS-319
2024-11-19 12:09:55 -05:00

25 lines
928 B
Swift

// Copyright © 2023 Mastodon gGmbH. All rights reserved.
import Foundation
import Intents
import MastodonCore
import MastodonSDK
import MastodonLocalization
@MainActor
class MultiFollowersCountIntentHandler: INExtension, MultiFollowersCountIntentHandling {
func provideAccountsOptionsCollection(for intent: MultiFollowersCountIntent, searchTerm: String?) async throws -> INObjectCollection<NSString> {
guard
let searchTerm = searchTerm,
let authenticationBox = AuthenticationServiceProvider.shared.currentActiveUser.value
else {
return INObjectCollection(items: [])
}
let results = try await APIService.shared
.search(query: .init(q: searchTerm), authenticationBox: authenticationBox)
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomainIfMissing(authenticationBox.domain) as NSString })
}
}