aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoreal <eal@waifu.club>2018-05-29 13:29:51 +0300
committereal <eal@waifu.club>2018-05-29 13:31:36 +0300
commit35cb8969c459668c831942cba876c5113f1c0f90 (patch)
treed73af03e6d7516f0d76ba584f7caf0907c58197b /lib
parent461f201caae68cd781240fa40f8b6502ba7e57cb (diff)
downloadpleroma-35cb8969c459668c831942cba876c5113f1c0f90.tar.gz
MastoAPI: Fix link headers with restrictive params.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 8dbbe3871..e89186ae3 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -144,7 +144,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
json(conn, mastodon_emoji)
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)
first = List.first(activities)
@@ -155,13 +155,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
{next_url, prev_url} =
if param do
{
- mastodon_api_url(Pleroma.Web.Endpoint, method, param, max_id: min),
- mastodon_api_url(Pleroma.Web.Endpoint, method, param, since_id: max)
+ mastodon_api_url(
+ 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
{
- mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min),
- mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max)
+ mastodon_api_url(
+ Pleroma.Web.Endpoint,
+ method,
+ Map.merge(params, %{max_id: min})
+ ),
+ mastodon_api_url(
+ Pleroma.Web.Endpoint,
+ method,
+ Map.merge(params, %{since_id: max})
+ )
}
end
@@ -189,10 +207,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def public_timeline(%{assigns: %{user: user}} = conn, params) do
+ local_only = params["local"] in [true, "True", "true", "1"]
+
params =
params
|> 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)
activities =
@@ -200,7 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Enum.reverse()
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})
end
@@ -225,7 +245,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
activities = Repo.all(query)
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})
end
@@ -406,10 +426,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
+ local_only = params["local"] in [true, "True", "true", "1"]
+
params =
params
|> Map.put("type", "Create")
- |> Map.put("local_only", !!params["local"])
+ |> Map.put("local_only", local_only)
|> Map.put("blocking_user", user)
activities =
@@ -417,7 +439,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Enum.reverse()
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})
end