2017-03-22 10:32:27 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-08 03:09:25 +09:00
|
|
|
class Api::V1::SearchController < Api::BaseController
|
2017-11-15 09:53:33 +09:00
|
|
|
include Authorization
|
|
|
|
|
2017-05-31 10:11:54 +09:00
|
|
|
RESULTS_LIMIT = 5
|
|
|
|
|
2017-07-12 00:08:26 +09:00
|
|
|
before_action -> { doorkeeper_authorize! :read }
|
|
|
|
before_action :require_user!
|
|
|
|
|
2017-03-22 10:32:27 +09:00
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def index
|
2017-11-15 09:53:33 +09:00
|
|
|
@search = Search.new(search)
|
2017-07-07 11:02:06 +09:00
|
|
|
render json: @search, serializer: REST::SearchSerializer
|
2017-05-31 10:11:54 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-11-15 09:53:33 +09:00
|
|
|
def search
|
|
|
|
search_results.tap do |search|
|
|
|
|
search[:statuses].keep_if do |status|
|
|
|
|
begin
|
|
|
|
authorize status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-31 10:11:54 +09:00
|
|
|
def search_results
|
|
|
|
SearchService.new.call(
|
|
|
|
params[:q],
|
|
|
|
RESULTS_LIMIT,
|
2018-03-01 10:47:59 +09:00
|
|
|
truthy_param?(:resolve),
|
2017-05-31 10:11:54 +09:00
|
|
|
current_account
|
|
|
|
)
|
|
|
|
end
|
2017-03-22 10:32:27 +09:00
|
|
|
end
|