From df1a44cc2193c9792fa5fbab772c8fa6f0917565 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 5 Dec 2023 21:03:47 +0100 Subject: [PATCH] Use V1 accounts API for autocomplete --- .../Network/Sources/Network/Endpoint/Search.swift | 6 +++++- .../Status/Editor/StatusEditorViewModel.swift | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Packages/Network/Sources/Network/Endpoint/Search.swift b/Packages/Network/Sources/Network/Endpoint/Search.swift index c111a3fb..69664578 100644 --- a/Packages/Network/Sources/Network/Endpoint/Search.swift +++ b/Packages/Network/Sources/Network/Endpoint/Search.swift @@ -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)) diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift index d1785563..81c44282 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift @@ -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