about summary refs log tree commit diff
path: root/app/controllers/api/v1/trends/statuses_controller.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-02-26 21:15:19 +0100
committerGitHub <noreply@github.com>2022-02-26 21:15:19 +0100
commit551820cbd9e5beebd16f16205143e2263d4f2d51 (patch)
tree6868722efeb660c0031a22aecfdc4b2c5bc9dcc6 /app/controllers/api/v1/trends/statuses_controller.rb
parente48eaf64cc7cb0cfab388331c4823ee5fb580d59 (diff)
parent67c6f37e269a4ebb538e019351f894183f3c1439 (diff)
Merge pull request #1704 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api/v1/trends/statuses_controller.rb')
-rw-r--r--app/controllers/api/v1/trends/statuses_controller.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/api/v1/trends/statuses_controller.rb b/app/controllers/api/v1/trends/statuses_controller.rb
new file mode 100644
index 000000000..d4ec97ae5
--- /dev/null
+++ b/app/controllers/api/v1/trends/statuses_controller.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class Api::V1::Trends::StatusesController < Api::BaseController
+  before_action :set_statuses
+
+  def index
+    render json: @statuses, each_serializer: REST::StatusSerializer
+  end
+
+  private
+
+  def set_statuses
+    @statuses = begin
+      if Setting.trends
+        cache_collection(statuses_from_trends, Status)
+      else
+        []
+      end
+    end
+  end
+
+  def statuses_from_trends
+    scope = Trends.statuses.query.allowed.in_locale(content_locale)
+    scope = scope.filtered_for(current_account) if user_signed_in?
+    scope.limit(limit_param(DEFAULT_STATUSES_LIMIT))
+  end
+end