aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-04-22 12:48:52 +0200
committerlain <lain@soykaf.club>2020-04-22 12:48:52 +0200
commit2e62a63749e040b108b8afe2c8839c470f89fa04 (patch)
treeebc0f2bb464c92c043c5ab9c1491edd8c831d865
parent6c8390fa4d47a86c34bcc71681ba30f04d14eae9 (diff)
downloadpleroma-2e62a63749e040b108b8afe2c8839c470f89fa04.tar.gz
ChatMessageValidator: Validation changes
Don't validate if the recipient is blocking the actor.
-rw-r--r--lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex12
-rw-r--r--test/web/activity_pub/object_validator_test.exs9
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex b/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
index 2feb65f29..8b5bb4fdc 100644
--- a/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
+++ b/lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
@@ -61,15 +61,25 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
|> validate_local_concern()
end
- @doc "Validates if at least one of the users in this ChatMessage is a local user, otherwise we don't want the message in our system. It also validates the presence of both users in our system."
+ @doc """
+ Validates the following
+ - If both users are in our system
+ - If at least one of the users in this ChatMessage is a local user
+ - If the recipient is not blocking the actor
+ """
def validate_local_concern(cng) do
with actor_ap <- get_field(cng, :actor),
{_, %User{} = actor} <- {:find_actor, User.get_cached_by_ap_id(actor_ap)},
{_, %User{} = recipient} <-
{:find_recipient, User.get_cached_by_ap_id(get_field(cng, :to) |> hd())},
+ {_, false} <- {:blocking_actor?, User.blocks?(recipient, actor)},
{_, true} <- {:local?, Enum.any?([actor, recipient], & &1.local)} do
cng
else
+ {:blocking_actor?, true} ->
+ cng
+ |> add_error(:actor, "actor is blocked by recipient")
+
{:local?, false} ->
cng
|> add_error(:actor, "actor and recipient are both remote")
diff --git a/test/web/activity_pub/object_validator_test.exs b/test/web/activity_pub/object_validator_test.exs
index 8230ae0d9..bc2317e55 100644
--- a/test/web/activity_pub/object_validator_test.exs
+++ b/test/web/activity_pub/object_validator_test.exs
@@ -33,6 +33,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
end
+ test "does not validate if the recipient is blocking the actor", %{
+ valid_chat_message: valid_chat_message,
+ user: user,
+ recipient: recipient
+ } do
+ Pleroma.User.block(recipient, user)
+ refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))
+ end
+
test "does not validate if the actor or the recipient is not in our system", %{
valid_chat_message: valid_chat_message
} do