forked from AkkomaGang/akkoma
Add user timelines to Masto Api.
This commit is contained in:
parent
b8912ff954
commit
7616b202ea
3 changed files with 32 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
alias Pleroma.{Repo, Activity}
|
alias Pleroma.{Repo, Activity, User}
|
||||||
alias Pleroma.Web.OAuth.App
|
alias Pleroma.Web.OAuth.App
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
|
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
|
||||||
|
@ -55,6 +55,19 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||||
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
|
render conn, StatusView, "index.json", %{activities: activities, for: user, as: :activity}
|
||||||
end
|
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
|
def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Activity{} = activity <- Repo.get(Activity, id) do
|
with %Activity{} = activity <- Repo.get(Activity, id) do
|
||||||
render conn, StatusView, "status.json", %{activity: activity, for: user}
|
render conn, StatusView, "status.json", %{activity: activity, for: user}
|
||||||
|
|
|
@ -48,6 +48,8 @@ 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 "/accounts/:id/statuses", MastodonAPIController, :user_statuses
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||||
|
|
|
@ -165,4 +165,20 @@ test "unfavorites a status and returns it", %{conn: conn} do
|
||||||
assert activity.id == id
|
assert activity.id == id
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue