diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca519a668..6aaadca42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object
- Experimental support for Finch. Put `config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}` in your secrets file to use it. Reverse Proxy will still use Hackney.
+- `ForceMentionsInPostContent` MRF policy
- AdminAPI: allow moderators to manage reports, users, invites, and custom emojis
- AdminAPI: restrict moderators to access sensitive data: change user credentials, get password reset token, read private statuses and chats, etc
- PleromaAPI: Add remote follow API endpoint at `POST /api/v1/pleroma/remote_interaction`
diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md
index 5b2410c16..4dacdc68c 100644
--- a/docs/configuration/cheatsheet.md
+++ b/docs/configuration/cheatsheet.md
@@ -126,6 +126,7 @@ To add configuration to your config file, you can copy it from the base config.
* `Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy`: Makes all bot posts to disappear from public timelines.
* `Pleroma.Web.ActivityPub.MRF.FollowBotPolicy`: Automatically follows newly discovered users from the specified bot account. Local accounts, locked accounts, and users with "#nobot" in their bio are respected and excluded from being followed.
* `Pleroma.Web.ActivityPub.MRF.KeywordPolicy`: Rejects or removes from the federated timeline or replaces keywords. (See [`:mrf_keyword`](#mrf_keyword)).
+ * `Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent`: Forces every mentioned user to be reflected in the post content.
* `transparency`: Make the content of your Message Rewrite Facility settings public (via nodeinfo).
* `transparency_exclusions`: Exclude specific instance names from MRF transparency. The use of the exclusions feature will be disclosed in nodeinfo as a boolean value.
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index ae37946ab..115835378 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -34,32 +34,34 @@ def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
def mention_handler("@" <> nickname, buffer, opts, acc) do
case User.get_cached_by_nickname(nickname) do
- %User{id: id} = user ->
- user_url = user.uri || user.ap_id
- nickname_text = get_nickname_text(nickname, opts)
-
- link =
- Phoenix.HTML.Tag.content_tag(
- :span,
- Phoenix.HTML.Tag.content_tag(
- :a,
- ["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)],
- "data-user": id,
- class: "u-url mention",
- href: user_url,
- rel: "ugc"
- ),
- class: "h-card"
- )
- |> Phoenix.HTML.safe_to_string()
-
- {link, %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, user})}}
+ %User{} = user ->
+ {mention_from_user(user, opts),
+ %{acc | mentions: MapSet.put(acc.mentions, {"@" <> nickname, user})}}
_ ->
{buffer, acc}
end
end
+ def mention_from_user(%User{id: id} = user, opts \\ %{mentions_format: :full}) do
+ user_url = user.uri || user.ap_id
+ nickname_text = get_nickname_text(user.nickname, opts)
+
+ Phoenix.HTML.Tag.content_tag(
+ :span,
+ Phoenix.HTML.Tag.content_tag(
+ :a,
+ ["@", Phoenix.HTML.Tag.content_tag(:span, nickname_text)],
+ "data-user": id,
+ class: "u-url mention",
+ href: user_url,
+ rel: "ugc"
+ ),
+ class: "h-card"
+ )
+ |> Phoenix.HTML.safe_to_string()
+ end
+
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
tag = String.downcase(tag)
url = "#{Pleroma.Web.Endpoint.url()}/tag/#{tag}"
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 0a5dfccc9..bf5b6508b 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -1055,6 +1055,10 @@ def get_by_ap_id(ap_id) do
Repo.get_by(User, ap_id: ap_id)
end
+ def get_by_uri(uri) do
+ Repo.get_by(User, uri: uri)
+ end
+
def get_all_by_ap_id(ap_ids) do
from(u in __MODULE__,
where: u.ap_id in ^ap_ids
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
new file mode 100644
index 000000000..522ae2f60
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/force_mentions_in_content.ex
@@ -0,0 +1,80 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors
Haha yeah, you can control who you reply to.
", + "context": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7", + "conversation": "https://gleasonator.com/contexts/ba6c8bd9-ac4d-479e-9bd9-5bf570068ae7", + "id": "https://gleasonator.com/objects/02af65fe-04f8-46bc-9b1e-31dfe76eaffd", + "inReplyTo": "https://shitposter.club/objects/c686d811-4368-48e1-ba11-82c129f93165", + "published": "2022-01-19T03:37:35.976545Z", + "sensitive": false, + "source": "Haha yeah, you can control who you reply to.", + "summary": "", + "tag": [ + { + "href": "https://lain.com/users/lain", + "name": "@lain@lain.com", + "type": "Mention" + }, + { + "href": "https://shitposter.club/users/coolboymew", + "name": "@coolboymew@shitposter.club", + "type": "Mention" + }, + { + "href": "https://shitposter.club/users/dielan", + "name": "@dielan@shitposter.club", + "type": "Mention" + }, + { + "href": "https://tuusin.misono-ya.info/users/hakui", + "name": "@hakui@tuusin.misono-ya.info", + "type": "Mention" + }, + { + "href": "https://xyzzy.link/users/fence", + "name": "@fence@xyzzy.link", + "type": "Mention" + } + ], + "to": [ + "https://shitposter.club/users/dielan", + "https://gleasonator.com/users/alex/followers", + "https://shitposter.club/users/coolboymew", + "https://xyzzy.link/users/fence", + "https://tuusin.misono-ya.info/users/hakui", + "https://lain.com/users/lain" + ], + "type": "Note" +} 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 new file mode 100644 index 000000000..090bdc35e --- /dev/null +++ b/test/pleroma/web/activity_pub/mrf/force_mentions_in_content_test.exs @@ -0,0 +1,34 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors