Add local timeline unauthenticated homepage
This commit is contained in:
parent
fcd66f3d51
commit
1a1a58cb82
|
@ -24,7 +24,7 @@ defmodule Clacks.Timeline do
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec home_timeline(user :: User.t(), params :: map()) :: [
|
@spec home_timeline(user :: User.t(), params :: map()) :: [
|
||||||
Activity.t()
|
{Activity.t(), Actor.t()}
|
||||||
]
|
]
|
||||||
def home_timeline(user, params) do
|
def home_timeline(user, params) do
|
||||||
user =
|
user =
|
||||||
|
@ -49,6 +49,18 @@ defmodule Clacks.Timeline do
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
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
|
defp restrict_to_actor(query, actor_id) do
|
||||||
where(query, [a], fragment("?->>'actor'", a.data) == ^actor_id)
|
where(query, [a], fragment("?->>'actor'", a.data) == ^actor_id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,12 +18,14 @@ defmodule ClacksWeb.FrontendController do
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(conn, params) do
|
||||||
Application.get_env(:clacks, :frontend, %{})
|
Application.get_env(:clacks, :frontend, %{})
|
||||||
|> Keyword.get(:unauthenticated_homepage, :public_timeline)
|
|> Keyword.get(:unauthenticated_homepage, :local_timeline)
|
||||||
|> index(conn, params)
|
|> index(conn, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp index(:public_timeline, conn, params) do
|
defp index(:local_timeline, conn, params) do
|
||||||
# tood: show public timeline
|
render(conn, "local_timeline.html", %{
|
||||||
|
statuses_with_authors: Timeline.local_timeline(params)
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
defp index({:profile, nickname}, conn, params) do
|
defp index({:profile, nickname}, conn, params) do
|
||||||
|
@ -36,8 +38,8 @@ defmodule ClacksWeb.FrontendController do
|
||||||
})
|
})
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
# otherwise show public timeline
|
# otherwise show local timeline
|
||||||
index(:public_timeline, conn)
|
index(:local_timeline, conn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ defmodule ClacksWeb.FrontendController do
|
||||||
data:
|
data:
|
||||||
%{
|
%{
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"object" => %{"type" => "Note", "attributedTo" => author_id} = note
|
"object" => %{"type" => "Note", "attributedTo" => author_id}
|
||||||
} = data
|
} = data
|
||||||
} = activity <- Activity.get(id),
|
} = activity <- Activity.get(id),
|
||||||
%Actor{} = author <- Actor.get_by_ap_id(author_id) do
|
%Actor{} = author <- Actor.get_by_ap_id(author_id) do
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<h1>Local Timeline</h1>
|
||||||
|
|
||||||
|
<%= render "_timeline.html", conn: @conn, statuses_with_authors: @statuses_with_authors %>
|
Loading…
Reference in New Issue