Add user timelines to Masto Api.

This commit is contained in:
Roger Braun 2017-09-10 17:46:43 +02:00
parent b8912ff954
commit 7616b202ea
3 changed files with 32 additions and 1 deletions

View File

@ -1,6 +1,6 @@
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
use Pleroma.Web, :controller
alias Pleroma.{Repo, Activity}
alias Pleroma.{Repo, Activity, User}
alias Pleroma.Web.OAuth.App
alias Pleroma.Web
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
@ -55,6 +55,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
end
def user_statuses(%{assigns: %{user: user}} = conn, params) do
with %User{ap_id: ap_id} <- Repo.get(User, params["id"]) do
params = params
|> Map.put("type", "Create")
|> Map.put("actor_id", ap_id)
activities = ActivityPub.fetch_activities([], params)
|> Enum.reverse
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
end
end
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Repo.get(Activity, id) do
render conn, StatusView, "status.json", %{activity: activity, for: user}

View File

@ -48,6 +48,8 @@ defmodule Pleroma.Web.Router do
get "/statuses/:id", MastodonAPIController, :get_status
get "/statuses/:id/context", MastodonAPIController, :get_context
get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
end
scope "/api/v1", Pleroma.Web.MastodonAPI do

View File

@ -165,4 +165,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert activity.id == id
end
end
describe "user timelines" do
test "gets a users statuses", %{conn: conn} do
_note = insert(:note_activity)
note_two = insert(:note_activity)
user = User.get_by_ap_id(note_two.data["actor"])
conn = conn
|> get("/api/v1/accounts/#{user.id}/statuses")
assert [%{"id" => id}] = json_response(conn, 200)
assert id == note_two.id
end
end
end