Browse Source

Use timeline module for outbox

master
Shadowfacts 1 year ago
parent
commit
0ca9d02499
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
2 changed files with 12 additions and 22 deletions
  1. +3
    -1
      lib/clacks/timeline.ex
  2. +9
    -21
      lib/clacks_web/controllers/outbox_controller.ex

+ 3
- 1
lib/clacks/timeline.ex View File

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


+ 9
- 21
lib/clacks_web/controllers/outbox_controller.ex View File

@ -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)
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)
%Actor{local: false} ->
_ ->
conn
|> put_status(404)
actor ->
assign(conn, :actor, actor)
|> 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…
Cancel
Save