Remerge of hashtag following #341

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

View file

@ -471,9 +471,15 @@ def run(["blocking", nickname]) do
def run(["timeline_query", nickname]) do
start_pleroma()
params = %{local: true}
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
followed_hashtags =
user
|> User.followed_hashtags()
|> Enum.map(& &1.id)
params =
params
|> Map.put(:type, ["Create", "Announce"])
@ -484,6 +490,7 @@ def run(["timeline_query", nickname]) 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 =

View file

@ -933,11 +933,19 @@ defp restrict_recipients(query, recipients, user) do
)
end
# Essentially, either look for activities addressed to `recipients`, _OR_ ones
# that reference a hashtag that the user follows
# Firstly, two fallbacks in case there's no hashtag constraint, or the user doesn't
# follow any
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
defp restrict_recipients_or_hashtags(query, recipients, user, []) 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",
@ -1395,7 +1403,7 @@ def fetch_activities_query(recipients, opts \\ %{}) do
|> maybe_preload_report_notes(opts)
|> maybe_set_thread_muted_field(opts)
|> maybe_order(opts)
|> restrict_recipients_or_hashtags(recipients, opts[:user], opts[:hashtags])
|> restrict_recipients_or_hashtags(recipients, opts[:user], opts[:followed_hashtags])
|> restrict_replies(opts)
|> restrict_since(opts)
|> restrict_local(opts)

View file

@ -55,7 +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.put(:followed_hashtags, followed_hashtags)
|> Map.delete(:local)
activities =

View file

@ -719,6 +719,24 @@ test "retrieve the activities for certain recipients" do
end
end
describe "fetch activities for followed hashtags" do
test "it should return public activities that reference a given hashtag" do
hashtag = insert(:hashtag, name: "tenshi")
user = insert(:user)
{:ok, public} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "public"})
{:ok, _unrelated} = CommonAPI.post(user, %{status: "dai #tensh", visibility: "public"})
{:ok, unlisted} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "unlisted"})
{:ok, _private} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "private"})
activities = ActivityPub.fetch_activities([], %{followed_hashtags: [hashtag.id]})
assert length(activities) == 2
public_id = public.id
unlisted_id = unlisted.id
assert [%{id: ^public_id}, %{id: ^unlisted_id}] = activities
end
end
describe "fetch activities in context" do
test "retrieves activities that have a given context" do
{:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})