Commit b8912ff9 authored by lain's avatar lain
Browse files

Fix masto api context.

parent 8672d4d1
...@@ -64,10 +64,11 @@ def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do ...@@ -64,10 +64,11 @@ def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do def get_context(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Repo.get(Activity, id), with %Activity{} = activity <- Repo.get(Activity, id),
activities <- ActivityPub.fetch_activities_for_context(activity.data["object"]["context"]), 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 activities <- activities |> Enum.filter(fn (%{id: aid}) -> to_string(aid) != to_string(id) end),
grouped_activities <- Enum.group_by(activities, fn (%{id: id}) -> id < activity.id end) do
result = %{ result = %{
ancestors: StatusView.render("index.json", for: user, activities: ancestors, as: :activity) |> Enum.reverse, ancestors: StatusView.render("index.json", for: user, activities: grouped_activities[true] || [], as: :activity) |> Enum.reverse,
descendants: StatusView.render("index.json", for: user, activities: descendants, as: :activity) |> Enum.reverse, descendants: StatusView.render("index.json", for: user, activities: grouped_activities[false] || [], as: :activity) |> Enum.reverse,
} }
json(conn, result) json(conn, result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment