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