Use timeline module for outbox
This commit is contained in:
parent
2972bad192
commit
0ca9d02499
|
@ -15,6 +15,7 @@ defmodule Clacks.Timeline do
|
|||
|> restrict_to_types(@timeline_types)
|
||||
|> restrict_to_public(only_public)
|
||||
|> paginate(params)
|
||||
|> limit(^Map.get(params, "limit", 20))
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
@ -35,8 +36,9 @@ defmodule Clacks.Timeline do
|
|||
fragment("?->>'actor'", a.data) == ^user.actor.ap_id or
|
||||
fragment("?->>'actor'", a.data) in ^user.actor.followers
|
||||
)
|
||||
|> restrict_to_types([@timeline_types])
|
||||
|> restrict_to_types(@timeline_types)
|
||||
|> paginate(params)
|
||||
|> limit(^Map.get(params, "limit", 20))
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
|
|
@ -1,32 +1,28 @@
|
|||
defmodule ClacksWeb.OutboxController do
|
||||
use ClacksWeb, :controller
|
||||
alias Clacks.{Repo, Actor, Activity}
|
||||
alias Clacks.{Repo, Actor, Activity, Timeline}
|
||||
import Ecto.Query
|
||||
|
||||
@context "https://www.w3.org/ns/activitystreams"
|
||||
@outbox_types ["Create", "Announce"]
|
||||
|
||||
plug :get_actor
|
||||
|
||||
defp get_actor(%Plug.Conn{path_params: %{"nickname" => nickname}} = conn, _opts) do
|
||||
case Actor.get_by_nickname(nickname) do
|
||||
nil ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|
||||
%Actor{local: false} ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|
||||
actor ->
|
||||
defp get_actor(%Plug.Conn{path_params: %{"username" => username}} = conn, _opts) do
|
||||
case Actor.get_by_nickname(username) do
|
||||
%Actor{local: true} = actor ->
|
||||
assign(conn, :actor, actor)
|
||||
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> json(%{error: "Not Found"})
|
||||
end
|
||||
end
|
||||
|
||||
def outbox(conn, params) when params == %{} do
|
||||
actor = conn.assigns[:actor]
|
||||
|
||||
activities = Repo.all(outbox_query(params, actor))
|
||||
activities = Timeline.actor_timeline(actor, true, params)
|
||||
|
||||
data = %{
|
||||
"@context" => @context,
|
||||
|
@ -43,7 +39,7 @@ defmodule ClacksWeb.OutboxController do
|
|||
def outbox(conn, params) do
|
||||
actor = conn.assigns[:actor]
|
||||
|
||||
activities = Repo.all(outbox_query(params, actor))
|
||||
activities = Timeline.actor_timeline(actor, true, params)
|
||||
|
||||
data =
|
||||
outbox_page(conn, params, activities)
|
||||
|
@ -54,14 +50,6 @@ defmodule ClacksWeb.OutboxController do
|
|||
|> json(data)
|
||||
end
|
||||
|
||||
defp outbox_query(params, %Actor{ap_id: ap_id}) do
|
||||
Activity
|
||||
|> where([a], a.actor == ^ap_id)
|
||||
|> where([a], fragment("?->>'type'", a.data) in @outbox_types)
|
||||
|> Clacks.Paginator.paginate(params)
|
||||
|> limit(^Map.get(params, "limit", 20))
|
||||
end
|
||||
|
||||
defp outbox_page(conn, pagination_params, activities) do
|
||||
last_id = List.last(activities).id
|
||||
|
||||
|
|
Loading…
Reference in New Issue