Add context to mastodonAPI.
authorRoger Braun <roger@rogerbraun.net>
Sun, 10 Sep 2017 13:00:13 +0000 (15:00 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 10 Sep 2017 13:00:13 +0000 (15:00 +0200)
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/router.ex

index 4401a37a39dab3645e96673e0130902143c8a343..900f9e3da1a15ada7f6d0fa693b2c42e262938e9 100644 (file)
@@ -61,6 +61,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
+  def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+    with %Activity{} = activity <- Repo.get(Activity, id),
+         activities <- ActivityPub.fetch_activities_for_context(activity.data["object"]["context"]),
+         %{true: ancestors, false: descendants} <- Enum.group_by(activities, fn (%{id: id}) -> id < activity.id end) do
+      result = %{
+        ancestors: StatusView.render("index.json", for: user, activities: ancestors, as: :activity) |> Enum.reverse,
+        descendants: StatusView.render("index.json", for: user, activities: descendants, as: :activity) |> Enum.reverse,
+      }
+
+      json(conn, result)
+    end
+  end
+
   def post_status(%{assigns: %{user: user}} = conn, %{"status" => status} = params) do
     l = status |> String.trim |> String.length
 
index 84bf6791dd2bbd29bbc4efcd323c95ed5c9471a1..5246b3c415ed45aebbfdde50eb915c805b56ae28 100644 (file)
@@ -47,6 +47,7 @@ defmodule Pleroma.Web.Router do
     get "/timelines/public", MastodonAPIController, :public_timeline
 
     get "/statuses/:id", MastodonAPIController, :get_status
+    get "/statuses/:id/context", MastodonAPIController, :get_context
   end
 
   scope "/api/v1", Pleroma.Web.MastodonAPI do