Add local timeline unauthenticated homepage

This commit is contained in:
Shadowfacts 2020-04-26 16:51:19 -04:00
parent fcd66f3d51
commit 1a1a58cb82
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 24 additions and 7 deletions

View File

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

View File

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

View File

@ -0,0 +1,3 @@
<h1>Local Timeline</h1>
<%= render "_timeline.html", conn: @conn, statuses_with_authors: @statuses_with_authors %>