Fix home timeline including statuses from followers instead of following
This commit is contained in:
parent
e0c8f8e142
commit
fcd66f3d51
|
@ -9,26 +9,24 @@ defmodule Clacks.Timeline do
|
|||
@spec actor_timeline(
|
||||
actor :: Actor.t(),
|
||||
params :: map(),
|
||||
only_public :: boolean(),
|
||||
actors :: boolean()
|
||||
only_public :: boolean()
|
||||
) :: [
|
||||
Activity.t()
|
||||
]
|
||||
def actor_timeline(actor, params, only_public \\ true, actors \\ false) do
|
||||
def actor_timeline(actor, params, only_public \\ true) do
|
||||
Activity
|
||||
|> restrict_to_actor(actor.ap_id)
|
||||
|> restrict_to_types(@timeline_types)
|
||||
|> restrict_to_public(only_public)
|
||||
|> paginate(params)
|
||||
|> limit(^Map.get(params, "limit", 20))
|
||||
|> join_with_actors(actors)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@spec home_timeline(user :: User.t(), params :: map(), actors :: boolean()) :: [
|
||||
@spec home_timeline(user :: User.t(), params :: map()) :: [
|
||||
Activity.t()
|
||||
]
|
||||
def home_timeline(user, params, actors \\ false) do
|
||||
def home_timeline(user, params) do
|
||||
user =
|
||||
case user.actor do
|
||||
%Ecto.Association.NotLoaded{} ->
|
||||
|
@ -39,15 +37,15 @@ defmodule Clacks.Timeline do
|
|||
end
|
||||
|
||||
Activity
|
||||
|> join_with_actors()
|
||||
|> where(
|
||||
[a],
|
||||
fragment("?->>'actor'", a.data) == ^user.actor.ap_id or
|
||||
fragment("?->>'actor'", a.data) in ^user.actor.followers
|
||||
[activity, actor],
|
||||
fragment("?->>'actor'", activity.data) == ^user.actor.ap_id or
|
||||
^user.actor.ap_id in actor.followers
|
||||
)
|
||||
|> restrict_to_types(@timeline_types)
|
||||
|> paginate(params)
|
||||
|> limit(^Map.get(params, "limit", 20))
|
||||
|> join_with_actors(actors)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
@ -69,11 +67,9 @@ defmodule Clacks.Timeline do
|
|||
|
||||
defp restrict_to_public(query, false), do: query
|
||||
|
||||
defp join_with_actors(query, true) do
|
||||
defp join_with_actors(query) do
|
||||
query
|
||||
|> join(:left, [o], a in Actor, on: a.ap_id == fragment("?->>'actor'", o.data))
|
||||
|> select([o, a], {o, a})
|
||||
end
|
||||
|
||||
defp join_with_actors(query, false), do: query
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ defmodule ClacksWeb.FrontendController do
|
|||
render(conn, "home.html", %{
|
||||
user: user,
|
||||
actor: user.actor,
|
||||
statuses_with_authors: Timeline.home_timeline(user, params, true)
|
||||
statuses_with_authors: Timeline.home_timeline(user, params)
|
||||
})
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue