X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fmastodon_api_controller.ex;h=dede0434db5d383c905b5ac746426d0978e932fd;hb=d2faee01eea3a0cc8eed95d749d41c4a26556a13;hp=1570af0f78fc95a146f4e776ff0bf1c90584c4d3;hpb=0df4a0f26d96442d80afed1d332602269e29b65e;p=akkoma diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 1570af0f7..dede0434d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.CommonAPI + import Ecto.Query import Logger def create_app(conn, params) do @@ -38,14 +39,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, response) end - defp add_link_headers(conn, activities) do + defp add_link_headers(conn, method, activities) 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, :home_timeline, max_id: min) - prev_url = mastodon_api_url(Pleroma.Web.Endpoint, :home_timeline, since_id: max) + next_url = mastodon_api_url(Pleroma.Web.Endpoint, method, max_id: min) + prev_url = mastodon_api_url(Pleroma.Web.Endpoint, method, since_id: max) conn |> put_resp_header("link", "<#{next_url}>; rel=\"next\", <#{prev_url}>; rel=\"prev\"") else @@ -58,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.reverse conn - |> add_link_headers(activities) + |> add_link_headers(:home_timeline, activities) |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end @@ -70,7 +71,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(:public_timeline, activities) + |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end def user_statuses(%{assigns: %{user: user}} = conn, params) do @@ -154,6 +157,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do notifications = Notification.for_user(user, params) result = Enum.map(notifications, fn (%{id: id, activity: activity, inserted_at: created_at}) -> actor = User.get_cached_by_ap_id(activity.data["actor"]) + created_at = NaiveDateTime.to_iso8601(created_at) case activity.data["type"] do "Create" -> %{id: id, type: "mention", created_at: created_at, account: AccountView.render("account.json", %{user: actor}), status: StatusView.render("status.json", %{activity: activity})} @@ -170,7 +174,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end) |> Enum.filter(&(&1)) - json(conn, result) + conn + |> add_link_headers(:notifications, notifications) + |> json(result) + end + + def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do + id = List.wrap(id) + q = from u in User, + where: u.id in ^id + targets = Repo.all(q) + render conn, AccountView, "relationships.json", %{user: user, targets: targets} end def empty_array(conn, _) do