mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-05-15 16:22:40 +00:00
4ef6b3c9bf
Force replies to followers-only posts to always be direct
55 lines
1.5 KiB
Elixir
55 lines
1.5 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.ForceFollowersOnlyReplyDirectPolicy do
|
|
@moduledoc "Forces direct scope on replies to followers-only activites"
|
|
|
|
alias Pleroma.User
|
|
|
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
|
|
@impl true
|
|
def filter(%{"type" => type, "object" => %{"inReplyTo" => parent_post_ap_id}} = activity)
|
|
when type in ["Create", "Update"] do
|
|
reply_user = User.get_cached_by_ap_id(activity["actor"])
|
|
|
|
if followers_only?(parent_post_ap_id) do
|
|
direct_to = activity["to"] -- [reply_user.follower_address]
|
|
|
|
activity =
|
|
activity
|
|
|> Map.put("cc", [])
|
|
|> Map.put("to", direct_to)
|
|
|> Map.put("directMessage", true)
|
|
|> put_in(["object", "cc"], [])
|
|
|> put_in(["object", "to"], direct_to)
|
|
|
|
{:ok, activity}
|
|
else
|
|
{:ok, activity}
|
|
end
|
|
end
|
|
|
|
@impl true
|
|
def filter(activity), do: {:ok, activity}
|
|
|
|
@impl true
|
|
def describe, do: {:ok, %{}}
|
|
|
|
defp followers_only?(parent_ap_id) do
|
|
with %Pleroma.Object{} = object <- Pleroma.Object.get_by_ap_id(parent_ap_id),
|
|
object_data <- Map.get(object, :data),
|
|
%Pleroma.User{} = user <- User.get_cached_by_ap_id(object_data["actor"]) do
|
|
if user.follower_address in object_data["to"] do
|
|
true
|
|
else
|
|
false
|
|
end
|
|
else
|
|
_ ->
|
|
false
|
|
end
|
|
end
|
|
end
|