logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: a9f78fe8e07df1fdd51f235090cd35b09c73aa34
parent: f29902a24148073df516225c341065221135f238
Author: lain <lain@soykaf.club>
Date:   Sun, 11 Mar 2018 14:43:53 +0100

Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop

Diffstat:

Mlib/pleroma/web/mastodon_api/mastodon_api_controller.ex27+++++++++++++++++++++------
Mlib/pleroma/web/router.ex1+
2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -135,14 +135,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json conn, mastodon_emoji end - defp add_link_headers(conn, method, activities) do + defp add_link_headers(conn, method, activities, param \\ false) do last = List.last(activities) first = List.first(activities) if last do min = last.id max = first.id - next_url = mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min) - prev_url = mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max) + {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) + } + else + { + mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min), + mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max) + } + end conn |> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"") else @@ -178,7 +187,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end - # TODO: Link headers def user_statuses(%{assigns: %{user: user}} = conn, params) do with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do params = params @@ -189,7 +197,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do activities = ActivityPub.fetch_public_activities(params) |> Enum.reverse - render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity} + conn + |> add_link_headers(:user_statuses, activities, params["id"]) + |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end end @@ -333,7 +343,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - # TODO: Link headers def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do params = params |> Map.put("type", "Create") @@ -344,6 +353,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.reverse conn + |> add_link_headers(:hashtag_timeline, activities, params["tag"]) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end @@ -614,6 +624,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, []) end + def empty_object(conn, _) do + Logger.debug("Unimplemented, returning an empty object") + json(conn, %{}) + end + def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do actor = User.get_cached_by_ap_id(activity.data["actor"]) created_at = NaiveDateTime.to_iso8601(created_at) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex @@ -132,6 +132,7 @@ defmodule Pleroma.Web.Router do get "/statuses/:id", MastodonAPIController, :get_status get "/statuses/:id/context", MastodonAPIController, :get_context + get "/statuses/:id/card", MastodonAPIController, :empty_object get "/statuses/:id/favourited_by", MastodonAPIController, :favourited_by get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by