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 { public enum Search: Endpoint {
case search(query: String, type: String?, offset: Int?, following: Bool?) case search(query: String, type: String?, offset: Int?, following: Bool?)
case accountsSearch(query: String, type: String?, offset: Int?, following: Bool?)
public func path() -> String { public func path() -> String {
switch self { switch self {
case .search: case .search:
"search" "search"
case .accountsSearch:
"accounts/search"
} }
} }
public func queryItems() -> [URLQueryItem]? { public func queryItems() -> [URLQueryItem]? {
switch self { 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)] var params: [URLQueryItem] = [.init(name: "q", value: query)]
if let type { if let type {
params.append(.init(name: "type", value: type)) params.append(.init(name: "type", value: type))

View file

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