MastoApi: Add blocking to fetches.

This commit is contained in:
Roger Braun 2017-11-02 22:53:34 +01:00
parent d89a7a0b34
commit 9b63647aff
1 changed files with 5 additions and 1 deletions

View File

@ -79,6 +79,7 @@ defp add_link_headers(conn, method, activities) do
def home_timeline(%{assigns: %{user: user}} = conn, params) do def home_timeline(%{assigns: %{user: user}} = conn, params) do
params = params params = params
|> Map.put("type", ["Create", "Announce"]) |> Map.put("type", ["Create", "Announce"])
|> Map.put("blocking_user", user)
activities = ActivityPub.fetch_activities([user.ap_id | user.following], params) activities = ActivityPub.fetch_activities([user.ap_id | user.following], params)
|> Enum.reverse |> Enum.reverse
@ -92,6 +93,7 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
params = params params = params
|> Map.put("type", ["Create", "Announce"]) |> Map.put("type", ["Create", "Announce"])
|> Map.put("local_only", !!params["local"]) |> Map.put("local_only", !!params["local"])
|> Map.put("blocking_user", user)
activities = ActivityPub.fetch_public_activities(params) activities = ActivityPub.fetch_public_activities(params)
|> Enum.reverse |> Enum.reverse
@ -123,7 +125,7 @@ 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"], %{"blocking_user" => user}),
activities <- activities |> Enum.filter(fn (%{id: aid}) -> to_string(aid) != to_string(id) end), 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 grouped_activities <- Enum.group_by(activities, fn (%{id: id}) -> id < activity.id end) do
result = %{ result = %{
@ -246,6 +248,7 @@ def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
params = params params = params
|> Map.put("type", "Create") |> Map.put("type", "Create")
|> Map.put("local_only", !!params["local"]) |> Map.put("local_only", !!params["local"])
|> Map.put("blocking_user", user)
activities = ActivityPub.fetch_public_activities(params) activities = ActivityPub.fetch_public_activities(params)
|> Enum.reverse |> Enum.reverse
@ -338,6 +341,7 @@ def favourites(%{assigns: %{user: user}} = conn, params) do
params = conn params = conn
|> Map.put("type", "Create") |> Map.put("type", "Create")
|> Map.put("favorited_by", user.ap_id) |> Map.put("favorited_by", user.ap_id)
|> Map.put("blocking_user", user)
activities = ActivityPub.fetch_activities([], params) activities = ActivityPub.fetch_activities([], params)
|> Enum.reverse |> Enum.reverse