From 5d963d52920c5692c6d4e3f71d2d6c44661c9cd1 Mon Sep 17 00:00:00 2001 From: Essem Date: Fri, 9 Feb 2024 20:14:41 -0600 Subject: [PATCH] Allow filtering by emoji on API --- .../api/v1/statuses/reactions_controller.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/statuses/reactions_controller.rb b/app/controllers/api/v1/statuses/reactions_controller.rb index eb4b6f3411af53..e6cee38fe0fc36 100644 --- a/app/controllers/api/v1/statuses/reactions_controller.rb +++ b/app/controllers/api/v1/statuses/reactions_controller.rb @@ -41,8 +41,20 @@ def set_reactions end def ordered_reactions - StatusReaction.where(status: @status) - .group(:status_id, :id, :account_id, :name, :custom_emoji_id) + filtered_reactions.group(:status_id, :id, :account_id, :name, :custom_emoji_id) + end + + def filtered_reactions + initial_reactions = StatusReaction.where(status: @status) + if filtered? + initial_reactions.where(name: params[:emoji]) + else + initial_reactions + end + end + + def filtered? + params[:emoji].present? end def value_for_reaction_me_column(account) @@ -91,6 +103,6 @@ def records_continue? end def pagination_params(core_params) - params_slice(:limit).merge(core_params) + params_slice(:limit, :emoji).merge(core_params) end end