28 lines
1.0 KiB
Swift
28 lines
1.0 KiB
Swift
|
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
import Intents
|
||
|
import MastodonCore
|
||
|
import MastodonSDK
|
||
|
import MastodonLocalization
|
||
|
|
||
|
class MultiFollowersCountIntentHandler: INExtension, MultiFollowersCountSmallIntentHandling {
|
||
|
func provideAccountsOptionsCollection(for intent: MultiFollowersCountSmallIntent, 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)
|
||
|
|
||
|
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomain(localDomain: authenticationBox.domain) as NSString })
|
||
|
}
|
||
|
}
|