Pleroma instance running on expired.mentality.rip https://expired.mentality.rip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
1.4 KiB

# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.MRF.NotifyLocalUsersPolicy do
alias Pleroma.User
@behaviour Pleroma.Web.ActivityPub.MRF
@moduledoc "Notifies all local users by configurable tag in subject field (only for admins)"
require Pleroma.Constants
@impl true
def filter(
%{
"type" => "Create",
"to" => to,
"actor" => actor,
"object" => object
} = message
)
when is_map(object) do
user = User.get_cached_by_ap_id(actor)
if user.is_admin and object["inReplyTo"] == nil do
tag = Pleroma.Config.get([:mrf_notifylocalusers, :tag])
if object["summary"] == tag do
ap_ids =
User.Query.build(%{local: true, internal: false, deactivated: false})
|> Pleroma.Repo.all()
|> Enum.map(fn s -> s.ap_id end)
to = to ++ ap_ids
object =
object
|> Map.put("to", to)
message =
message
|> Map.put("to", to)
|> Map.put("object", object)
{:ok, message}
else
{:ok, message}
end
else
{:ok, message}
end
end
@impl true
def filter(message), do: {:ok, message}
@impl true
def describe, do: {:ok, %{}}
end