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

This commit is contained in:
lain 2018-03-11 14:43:53 +01:00
commit a9f78fe8e0
2 changed files with 22 additions and 6 deletions

View file

@ -135,14 +135,23 @@ def custom_emojis(conn, _params) do
json conn, mastodon_emoji json conn, mastodon_emoji
end end
defp add_link_headers(conn, method, activities) do defp add_link_headers(conn, method, activities, param \\ false) do
last = List.last(activities) last = List.last(activities)
first = List.first(activities) first = List.first(activities)
if last do if last do
min = last.id min = last.id
max = first.id max = first.id
next_url = mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min) {next_url, prev_url} = if param do
prev_url = mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max) {
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 conn
|> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"") |> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"")
else else
@ -178,7 +187,6 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
# TODO: Link headers
def user_statuses(%{assigns: %{user: user}} = conn, params) do def user_statuses(%{assigns: %{user: user}} = conn, params) do
with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do
params = params params = params
@ -189,7 +197,9 @@ def user_statuses(%{assigns: %{user: user}} = conn, params) do
activities = ActivityPub.fetch_public_activities(params) activities = ActivityPub.fetch_public_activities(params)
|> Enum.reverse |> 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
end end
@ -333,7 +343,6 @@ def reblogged_by(conn, %{"id" => id}) do
end end
end end
# TODO: Link headers
def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
params = params params = params
|> Map.put("type", "Create") |> Map.put("type", "Create")
@ -344,6 +353,7 @@ def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do
|> Enum.reverse |> Enum.reverse
conn conn
|> add_link_headers(:hashtag_timeline, activities, params["tag"])
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
end end
@ -614,6 +624,11 @@ def empty_array(conn, _) do
json(conn, []) json(conn, [])
end 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 def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do
actor = User.get_cached_by_ap_id(activity.data["actor"]) actor = User.get_cached_by_ap_id(activity.data["actor"])
created_at = NaiveDateTime.to_iso8601(created_at) created_at = NaiveDateTime.to_iso8601(created_at)

View file

@ -132,6 +132,7 @@ def user_fetcher(username) do
get "/statuses/:id", MastodonAPIController, :get_status get "/statuses/:id", MastodonAPIController, :get_status
get "/statuses/:id/context", MastodonAPIController, :get_context 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/favourited_by", MastodonAPIController, :favourited_by
get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by get "/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by