This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2023-08-24 16:40:04 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesSearchService < BaseService
|
|
|
|
def call(query, account = nil, options = {})
|
|
|
|
@query = query&.strip
|
|
|
|
@account = account
|
|
|
|
@options = options
|
|
|
|
@limit = options[:limit].to_i
|
|
|
|
@offset = options[:offset].to_i
|
|
|
|
|
|
|
|
status_search_results
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def status_search_results
|
2023-09-04 17:20:35 +02:00
|
|
|
request = parsed_query.request
|
|
|
|
results = request.collapse(field: :id).order(id: { order: :desc }).limit(@limit).offset(@offset).objects.compact
|
2023-08-24 16:40:04 +02:00
|
|
|
account_ids = results.map(&:account_id)
|
|
|
|
account_domains = results.map(&:account_domain)
|
|
|
|
preloaded_relations = @account.relations_map(account_ids, account_domains)
|
|
|
|
|
|
|
|
results.reject { |status| StatusFilter.new(status, @account, preloaded_relations).filtered? }
|
|
|
|
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def parsed_query
|
2023-08-28 12:43:00 +02:00
|
|
|
SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query), current_account: @account)
|
2023-08-24 16:40:04 +02:00
|
|
|
end
|
|
|
|
end
|