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}
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}
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
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