summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2024-08-12 20:25:19 +0000
committerfeld <feld@feld.me>2024-08-12 20:25:19 +0000
commitc29441f30d0229192868ec4149a46fea562b0997 (patch)
tree2e5e9d4b06133615aac5cdc302a62a5ff57681f1 /lib
parentaa4f5428d34c6d917d6efab96cfb3f2913d9e53a (diff)
parent471f5c81fd279ccbc0cee7196573485b8608786b (diff)
downloadpleroma-c29441f30d0229192868ec4149a46fea562b0997.tar.gz
pleroma-c29441f30d0229192868ec4149a46fea562b0997.zip
Merge branch 'mrf-quietreply' into 'develop'
MRF.QuietReply See merge request pleroma/pleroma!4213
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/mrf/quiet_reply.ex60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/pleroma/web/activity_pub/mrf/quiet_reply.ex b/lib/pleroma/web/activity_pub/mrf/quiet_reply.ex
new file mode 100644
index 000000000..ae5e2cdc7
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/quiet_reply.ex
@@ -0,0 +1,60 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.QuietReply do
+ @moduledoc """
+ QuietReply alters the scope of activities from local users when replying by enforcing them to be "Unlisted" or "Quiet Public". This delivers the activity to all the expected recipients and instances, but it will not be published in the Federated / The Whole Known Network timelines. It will still be published to the Home timelines of the user's followers and visible to anyone who opens the thread.
+ """
+ require Pleroma.Constants
+
+ alias Pleroma.User
+
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
+
+ @impl true
+ def history_awareness, do: :auto
+
+ @impl true
+ def filter(
+ %{
+ "type" => "Create",
+ "to" => to,
+ "cc" => cc,
+ "object" => %{
+ "actor" => actor,
+ "type" => "Note",
+ "inReplyTo" => in_reply_to
+ }
+ } = object
+ ) do
+ with true <- is_binary(in_reply_to),
+ false <- match?([], cc),
+ %User{follower_address: followers_collection, local: true} <-
+ User.get_by_ap_id(actor) do
+ updated_to =
+ to
+ |> Kernel.++([followers_collection])
+ |> Kernel.--([Pleroma.Constants.as_public()])
+
+ updated_cc = [Pleroma.Constants.as_public()]
+
+ updated_object =
+ object
+ |> Map.put("to", updated_to)
+ |> Map.put("cc", updated_cc)
+ |> put_in(["object", "to"], updated_to)
+ |> put_in(["object", "cc"], updated_cc)
+
+ {:ok, updated_object}
+ else
+ _ -> {:ok, object}
+ end
+ end
+
+ @impl true
+ def filter(object), do: {:ok, object}
+
+ @impl true
+ def describe, do: {:ok, %{}}
+end