logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 6611c6ce4ef3fe76bc9a5eb53677d3b6cde22793
parent 55dd8ef1c799bcfee803e68028af733a697711d1
Author: Lain Soykaf <lain@lain.com>
Date:   Sun, 11 Jun 2023 16:45:31 +0400

B ForceMentionsInContent: Fix test, refactor.

Diffstat:

Mlib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex8+++++---
Mtest/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs2+-
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex b/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex @@ -95,11 +95,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent do |> Enum.reject(&is_nil/1) |> sort_replied_user(replied_to_user) - explicitly_mentioned_uris = extract_mention_uris_from_content(content) + explicitly_mentioned_uris = + extract_mention_uris_from_content(content) + |> MapSet.new() added_mentions = - Enum.reduce(mention_users, "", fn %User{ap_id: api_id, uri: uri} = user, acc -> - unless Enum.any?([api_id, uri], fn u -> u in explicitly_mentioned_uris end) do + Enum.reduce(mention_users, "", fn %User{ap_id: ap_id, uri: uri} = user, acc -> + if MapSet.disjoint?(MapSet.new([ap_id, uri]), explicitly_mentioned_uris) do acc <> Formatter.mention_from_user(user, %{mentions_format: :compact}) <> " " else acc diff --git a/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs @@ -282,7 +282,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionsInContentTest do {:ok, post} = CommonAPI.post(rogerick, %{status: "eugh"}) inline_mentions = [ - "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{rogerick.id}\" href=\"#{rogerick.uri}\" rel=\"ugc\">@<span>rogerick</span></a></span>", + "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{rogerick.id}\" href=\"#{rogerick.ap_id}\" rel=\"ugc\">@<span>rogerick</span></a></span>", "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"#{greg.id}\" href=\"#{greg.uri}\" rel=\"ugc\">@<span>greg</span></a></span>" ]