Fix sending empty search query to Mastodon API (#101)

This commit is contained in:
prplecake 2022-11-07 17:47:56 -06:00 committed by GitHub
parent ffb880b59f
commit 70c9a40edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,6 +36,10 @@ extension SearchService: CollectionService {
public func request(maxId: String?, minId: String?, search: Search?) -> AnyPublisher<Never, Error> { public func request(maxId: String?, minId: String?, search: Search?) -> AnyPublisher<Never, Error> {
guard let search = search else { return Empty().eraseToAnyPublisher() } guard let search = search else { return Empty().eraseToAnyPublisher() }
if (search.query.trimmingCharacters(in: .whitespaces).isEmpty){
return Empty().eraseToAnyPublisher()
}
return mastodonAPIClient.request(ResultsEndpoint.search(search)) return mastodonAPIClient.request(ResultsEndpoint.search(search))
.flatMap { results in contentDatabase.insert(results: results).collect().map { _ in results } } .flatMap { results in contentDatabase.insert(results: results).collect().map { _ in results } }
.handleEvents(receiveOutput: { resultsSubject.send(($0, search)) }) .handleEvents(receiveOutput: { resultsSubject.send(($0, search)) })