Remerge of hashtag following #341

Merged
floatingghost merged 10 commits from follow-hashtags into develop 2022-12-05 12:58:48 +00:00
3 changed files with 35 additions and 1 deletions
Showing only changes of commit 9a10c0a5c9 - Show all commits

View file

@ -2568,6 +2568,19 @@ defp maybe_load_followed_hashtags(%User{} = user) do
%{user | followed_hashtags: followed_hashtags}
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
Logger.debug("Follow hashtag #{hashtag.name} for user #{user.nickname}")
user = maybe_load_followed_hashtags(user)

View file

@ -933,6 +933,21 @@ defp restrict_recipients(query, recipients, user) do
)
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
from(activity in query, where: activity.local == true)
end
@ -1380,7 +1395,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|> maybe_preload_report_notes(opts)
|> maybe_set_thread_muted_field(opts)
|> maybe_order(opts)
|> restrict_recipients(recipients, opts[:user])
|> restrict_recipients_or_hashtags(recipients, opts[:user], opts[:hashtags])
|> restrict_replies(opts)
|> restrict_since(opts)
|> restrict_local(opts)

View file

@ -41,6 +41,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
# GET /api/v1/timelines/home
def home(%{assigns: %{user: user}} = conn, params) do
followed_hashtags =
user
|> User.followed_hashtags()
|> Enum.map(& &1.id)
params =
params
|> 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(:user, user)
|> Map.put(:local_only, params[:local])
|> Map.put(:hashtags, followed_hashtags)
|> Map.delete(:local)
activities =