Use V1 accounts API for autocomplete

This commit is contained in:
Thomas Ricouard 2023-12-05 21:03:47 +01:00
parent 330aa93437
commit df1a44cc21
2 changed files with 11 additions and 7 deletions

View file

@ -2,17 +2,21 @@ import Foundation
public enum Search: Endpoint {
case search(query: String, type: String?, offset: Int?, following: Bool?)
case accountsSearch(query: String, type: String?, offset: Int?, following: Bool?)
public func path() -> String {
switch self {
case .search:
"search"
case .accountsSearch:
"accounts/search"
}
}
public func queryItems() -> [URLQueryItem]? {
switch self {
case let .search(query, type, offset, following):
case let .search(query, type, offset, following),
let .accountsSearch(query, type, offset, following):
var params: [URLQueryItem] = [.init(name: "q", value: query)]
if let type {
params.append(.init(name: "type", value: type))

View file

@ -482,16 +482,16 @@ import SwiftUI
}
case "@":
query.removeFirst()
results = try await client.get(endpoint: Search.search(query: query,
type: "accounts",
offset: 0,
following: true),
forceVersion: .v2)
let accounts: [Account] = try await client.get(endpoint: Search.accountsSearch(query: query,
type: nil,
offset: 0,
following: nil),
forceVersion: .v1)
guard !Task.isCancelled else {
return
}
withAnimation {
mentionsSuggestions = results?.accounts ?? []
mentionsSuggestions = accounts
}
default:
break