forked from AkkomaGang/akkoma
add followed hashtags into home timeline
This commit is contained in:
parent
aa10754a0f
commit
06d231e783
3 changed files with 35 additions and 1 deletions
|
@ -2568,6 +2568,19 @@ defp maybe_load_followed_hashtags(%User{} = user) do
|
||||||
%{user | followed_hashtags: followed_hashtags}
|
%{user | followed_hashtags: followed_hashtags}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def followed_hashtags(%User{followed_hashtags: follows})
|
||||||
|
when is_list(follows),
|
||||||
|
do: follows
|
||||||
|
|
||||||
|
def followed_hashtags(%User{} = user) do
|
||||||
|
{:ok, user} =
|
||||||
|
user
|
||||||
|
|> maybe_load_followed_hashtags()
|
||||||
|
|> set_cache()
|
||||||
|
|
||||||
|
user.followed_hashtags
|
||||||
|
end
|
||||||
|
|
||||||
def follow_hashtag(%User{} = user, %Hashtag{} = hashtag) do
|
def follow_hashtag(%User{} = user, %Hashtag{} = hashtag) do
|
||||||
Logger.debug("Follow hashtag #{hashtag.name} for user #{user.nickname}")
|
Logger.debug("Follow hashtag #{hashtag.name} for user #{user.nickname}")
|
||||||
user = maybe_load_followed_hashtags(user)
|
user = maybe_load_followed_hashtags(user)
|
||||||
|
|
|
@ -933,6 +933,21 @@ defp restrict_recipients(query, recipients, user) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp restrict_recipients_or_hashtags(query, recipients, user, nil) do
|
||||||
|
restrict_recipients(query, recipients, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp restrict_recipients_or_hashtags(query, recipients, user, hashtag_ids) do
|
||||||
|
from(
|
||||||
|
[activity, object] in query,
|
||||||
|
join: hto in "hashtags_objects",
|
||||||
|
on: hto.object_id == object.id,
|
||||||
|
where:
|
||||||
|
(hto.hashtag_id in ^hashtag_ids and ^Constants.as_public() in activity.recipients) or
|
||||||
|
fragment("? && ?", ^recipients, activity.recipients)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp restrict_local(query, %{local_only: true}) do
|
defp restrict_local(query, %{local_only: true}) do
|
||||||
from(activity in query, where: activity.local == true)
|
from(activity in query, where: activity.local == true)
|
||||||
end
|
end
|
||||||
|
@ -1380,7 +1395,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|
||||||
|> maybe_preload_report_notes(opts)
|
|> maybe_preload_report_notes(opts)
|
||||||
|> maybe_set_thread_muted_field(opts)
|
|> maybe_set_thread_muted_field(opts)
|
||||||
|> maybe_order(opts)
|
|> maybe_order(opts)
|
||||||
|> restrict_recipients(recipients, opts[:user])
|
|> restrict_recipients_or_hashtags(recipients, opts[:user], opts[:hashtags])
|
||||||
|> restrict_replies(opts)
|
|> restrict_replies(opts)
|
||||||
|> restrict_since(opts)
|
|> restrict_since(opts)
|
||||||
|> restrict_local(opts)
|
|> restrict_local(opts)
|
||||||
|
|
|
@ -41,6 +41,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|
|
||||||
# GET /api/v1/timelines/home
|
# GET /api/v1/timelines/home
|
||||||
def home(%{assigns: %{user: user}} = conn, params) do
|
def home(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
followed_hashtags =
|
||||||
|
user
|
||||||
|
|> User.followed_hashtags()
|
||||||
|
|> Enum.map(& &1.id)
|
||||||
|
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Map.put(:type, ["Create", "Announce"])
|
|> Map.put(:type, ["Create", "Announce"])
|
||||||
|
@ -50,6 +55,7 @@ def home(%{assigns: %{user: user}} = conn, params) do
|
||||||
|> Map.put(:announce_filtering_user, user)
|
|> Map.put(:announce_filtering_user, user)
|
||||||
|> Map.put(:user, user)
|
|> Map.put(:user, user)
|
||||||
|> Map.put(:local_only, params[:local])
|
|> Map.put(:local_only, params[:local])
|
||||||
|
|> Map.put(:hashtags, followed_hashtags)
|
||||||
|> Map.delete(:local)
|
|> Map.delete(:local)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
|
|
Loading…
Reference in a new issue