Commit 35cb8969 authored by eal's avatar eal

MastoAPI: Fix link headers with restrictive params.

parent 461f201c
...@@ -144,7 +144,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -144,7 +144,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
json(conn, mastodon_emoji) json(conn, mastodon_emoji)
end end
defp add_link_headers(conn, method, activities, param \\ false) do defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do
last = List.last(activities) last = List.last(activities)
first = List.first(activities) first = List.first(activities)
...@@ -155,13 +155,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -155,13 +155,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
{next_url, prev_url} = {next_url, prev_url} =
if param do if param do
{ {
mastodon_api_url(Pleroma.Web.Endpoint, method, param, max_id: min), mastodon_api_url(
mastodon_api_url(Pleroma.Web.Endpoint, method, param, since_id: max) Pleroma.Web.Endpoint,
method,
param,
Map.merge(params, %{max_id: min})
),
mastodon_api_url(
Pleroma.Web.Endpoint,
method,
param,
Map.merge(params, %{since_id: max})
)
} }
else else
{ {
mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min), mastodon_api_url(
mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max) Pleroma.Web.Endpoint,
method,
Map.merge(params, %{max_id: min})
),
mastodon_api_url(
Pleroma.Web.Endpoint,
method,
Map.merge(params, %{since_id: max})
)
} }
end end
...@@ -189,10 +207,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -189,10 +207,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
def public_timeline(%{assigns: %{user: user}} = conn, params) do def public_timeline(%{assigns: %{user: user}} = conn, params) do
local_only = params["local"] in [true, "True", "true", "1"]
params = params =
params params
|> Map.put("type", ["Create", "Announce"]) |> Map.put("type", ["Create", "Announce"])
|> Map.put("local_only", params["local"] in [true, "True", "true", "1"]) |> Map.put("local_only", local_only)
|> Map.put("blocking_user", user) |> Map.put("blocking_user", user)
activities = activities =
...@@ -200,7 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -200,7 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Enum.reverse() |> Enum.reverse()
conn conn
|> add_link_headers(:public_timeline, activities) |> add_link_headers(:public_timeline, activities, false, %{"local" => local_only})
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
...@@ -225,7 +245,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -225,7 +245,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
activities = Repo.all(query) activities = Repo.all(query)
conn conn
|> add_link_headers(:user_statuses, activities, user.ap_id) |> add_link_headers(:dm_timeline, activities)
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
...@@ -406,10 +426,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -406,10 +426,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end end
def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
local_only = params["local"] in [true, "True", "true", "1"]
params = params =
params params
|> Map.put("type", "Create") |> Map.put("type", "Create")
|> Map.put("local_only", !!params["local"]) |> Map.put("local_only", local_only)
|> Map.put("blocking_user", user) |> Map.put("blocking_user", user)
activities = activities =
...@@ -417,7 +439,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ...@@ -417,7 +439,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Enum.reverse() |> Enum.reverse()
conn conn
|> add_link_headers(:hashtag_timeline, activities, params["tag"]) |> add_link_headers(:hashtag_timeline, activities, params["tag"], %{"local" => local_only})
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
......
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