activitypub: add optional order constraint to timeline query builder
authorWilliam Pitcock <nenolod@dereferenced.org>
Tue, 7 May 2019 19:30:27 +0000 (19:30 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 7 May 2019 19:33:22 +0000 (19:33 +0000)
lib/pleroma/web/activity_pub/activity_pub.ex

index a4053986feb27936df997bc0f2e7df8fa1ef2868..8f8c23a9b1b439c04f6876bfe7b29e176185d3d9 100644 (file)
@@ -822,12 +822,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> Activity.with_preloaded_bookmark(opts["user"])
   end
 
+  defp maybe_order(query, %{order: :desc}) do
+    query
+    |> order_by(desc: :id)
+  end
+
+  defp maybe_order(query, %{order: :asc}) do
+    query
+    |> order_by(asc: :id)
+  end
+
+  defp maybe_order(query, _), do: query
+
   def fetch_activities_query(recipients, opts \\ %{}) do
     base_query = from(activity in Activity)
 
     base_query
     |> maybe_preload_objects(opts)
     |> maybe_preload_bookmarks(opts)
+    |> maybe_order(opts)
     |> restrict_recipients(recipients, opts["user"])
     |> restrict_tag(opts)
     |> restrict_tag_reject(opts)