aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-09-10 15:00:13 +0200
committerRoger Braun <roger@rogerbraun.net>2017-09-10 15:00:13 +0200
commit8672d4d12b7be3689386567ee93869292275439c (patch)
tree7d8be05ba2bdf5016241db08bbe11636b954dc1e /lib
parentfc10875895abd9add5a7834c4b5a64cc5b9401f8 (diff)
downloadpleroma-8672d4d12b7be3689386567ee93869292275439c.tar.gz
Add context to mastodonAPI.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex13
-rw-r--r--lib/pleroma/web/router.ex1
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 4401a37a3..900f9e3da 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -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
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 84bf6791d..5246b3c41 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -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