Created
April 23, 2022 12:06
-
-
Save BeeFox-sys/bf70ba3e72046d0439eb1e1ef7c4dade to your computer and use it in GitHub Desktop.
Obliterate Ableism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pleroma: A lightweight social networking server | |
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> | |
# SPDX-License-Identifier: AGPL-3.0-only | |
defmodule Pleroma.Web.ActivityPub.MRF.UnlistUndescribedMedia do | |
alias Pleroma.User | |
@moduledoc "Unlists posts with media that does not have a description, written by [email protected]" | |
@behaviour Pleroma.Web.ActivityPub.MRF.Policy | |
require Pleroma.Constants | |
defp check_media(%{"attachment" => attachments}), | |
do: not Enum.all?(attachments, fn x -> x["name"] != nil && x["name"] |> String.trim() != "" end) | |
defp check_media(_), | |
do: false | |
def filter( | |
%{ | |
"type" => "Create", | |
"to" => to, | |
"cc" => cc, | |
"actor" => actor, | |
"object" => object | |
} = message | |
) do | |
user = User.get_cached_by_ap_id(actor) | |
undescribed = check_media(object) | |
# unlist | |
if undescribed and Enum.member?(to, Pleroma.Constants.as_public()) do | |
to = List.delete(to, Pleroma.Constants.as_public()) ++ [user.follower_address] | |
cc = List.delete(cc, user.follower_address) ++ [Pleroma.Constants.as_public()] | |
object = | |
object | |
|> Map.put("to", to) | |
|> Map.put("cc", cc) | |
message = | |
message | |
|> Map.put("to", to) | |
|> Map.put("cc", cc) | |
|> Map.put("object", object) | |
{:ok, message} | |
else | |
{:ok, message} | |
end | |
end | |
@impl true | |
def filter(message), do: {:ok, message} | |
@impl true | |
def describe, do: {:ok, %{}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment