pleroma/lib/pleroma/web/activity_pub/mrf/notify_local_users_policy.ex

56 lines
1.4 KiB
Elixir
Raw Normal View History

# 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