From 1a1a58cb822a7c13feca71921f73ddc02248f2b2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 26 Apr 2020 16:51:19 -0400 Subject: [PATCH] Add local timeline unauthenticated homepage --- lib/clacks/timeline.ex | 14 +++++++++++++- lib/clacks_web/controllers/frontend_controller.ex | 14 ++++++++------ .../templates/frontend/local_timeline.html.eex | 3 +++ 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 lib/clacks_web/templates/frontend/local_timeline.html.eex diff --git a/lib/clacks/timeline.ex b/lib/clacks/timeline.ex index 2462866..84575e6 100644 --- a/lib/clacks/timeline.ex +++ b/lib/clacks/timeline.ex @@ -24,7 +24,7 @@ defmodule Clacks.Timeline do end @spec home_timeline(user :: User.t(), params :: map()) :: [ - Activity.t() + {Activity.t(), Actor.t()} ] def home_timeline(user, params) do user = @@ -49,6 +49,18 @@ defmodule Clacks.Timeline do |> Repo.all() end + @spec local_timeline(params :: map()) :: [{Activity.t(), Actor.t()}] + def local_timeline(params) do + Activity + |> where([a], a.local) + |> restrict_to_public(true) + |> restrict_to_types(@timeline_types) + |> paginate(params) + |> limit(^Map.get(params, "limit", 20)) + |> join_with_actors() + |> Repo.all() + end + defp restrict_to_actor(query, actor_id) do where(query, [a], fragment("?->>'actor'", a.data) == ^actor_id) end diff --git a/lib/clacks_web/controllers/frontend_controller.ex b/lib/clacks_web/controllers/frontend_controller.ex index df2fff2..4db431d 100644 --- a/lib/clacks_web/controllers/frontend_controller.ex +++ b/lib/clacks_web/controllers/frontend_controller.ex @@ -18,12 +18,14 @@ defmodule ClacksWeb.FrontendController do def index(conn, params) do Application.get_env(:clacks, :frontend, %{}) - |> Keyword.get(:unauthenticated_homepage, :public_timeline) + |> Keyword.get(:unauthenticated_homepage, :local_timeline) |> index(conn, params) end - defp index(:public_timeline, conn, params) do - # tood: show public timeline + defp index(:local_timeline, conn, params) do + render(conn, "local_timeline.html", %{ + statuses_with_authors: Timeline.local_timeline(params) + }) end defp index({:profile, nickname}, conn, params) do @@ -36,8 +38,8 @@ defmodule ClacksWeb.FrontendController do }) _ -> - # otherwise show public timeline - index(:public_timeline, conn) + # otherwise show local timeline + index(:local_timeline, conn) end end @@ -53,7 +55,7 @@ defmodule ClacksWeb.FrontendController do data: %{ "type" => "Create", - "object" => %{"type" => "Note", "attributedTo" => author_id} = note + "object" => %{"type" => "Note", "attributedTo" => author_id} } = data } = activity <- Activity.get(id), %Actor{} = author <- Actor.get_by_ap_id(author_id) do diff --git a/lib/clacks_web/templates/frontend/local_timeline.html.eex b/lib/clacks_web/templates/frontend/local_timeline.html.eex new file mode 100644 index 0000000..44a361c --- /dev/null +++ b/lib/clacks_web/templates/frontend/local_timeline.html.eex @@ -0,0 +1,3 @@ +

Local Timeline

+ +<%= render "_timeline.html", conn: @conn, statuses_with_authors: @statuses_with_authors %>