1
0
mirror of https://git.pleroma.social/sjw/pleroma.git synced 2024-12-27 23:25:37 +01:00

Fix masto api context.

This commit is contained in:
Roger Braun 2017-09-10 17:20:53 +02:00
parent 8672d4d12b
commit b8912ff954

View File

@ -64,10 +64,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
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
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 = %{
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,
ancestors: StatusView.render("index.json", for: user, activities: grouped_activities[true] || [], as: :activity) |> Enum.reverse,
descendants: StatusView.render("index.json", for: user, activities: grouped_activities[false] || [], as: :activity) |> Enum.reverse,
}
json(conn, result)