diff options
author | Mark Felder <feld@feld.me> | 2024-08-08 14:12:44 -0400 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2024-08-08 14:12:44 -0400 |
commit | a0af6cba09f6c85f524d31f7d1a68948b77d9e53 (patch) | |
tree | 3fb3ce849cf4c0c3d9f49ebd6b7e23132b1d6c10 /lib | |
parent | 540e62c5fcab3887d7ca488cb3f464f000f69523 (diff) | |
download | pleroma-a0af6cba09f6c85f524d31f7d1a68948b77d9e53.tar.gz pleroma-a0af6cba09f6c85f524d31f7d1a68948b77d9e53.zip |
Added MRF.QuietReply which prevents replies to public posts from being published to the timelines
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/mrf/quiet_reply.ex | 55 |
1 files changed, 55 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..8a9b2beb8 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/quiet_reply.ex @@ -0,0 +1,55 @@ +# 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 + 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", + "object" => %{ + "actor" => actor, + "type" => "Note", + "to" => to, + "cc" => cc, + "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 + |> 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 |