object_validator: Simplify Add/Remove
This commit is contained in:
parent
3f58213646
commit
f5fdc5dc63
@ -143,7 +143,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
|
||||
def validate(%{"type" => type} = object, meta)
|
||||
when type in ~w[Accept Reject Follow Update Like EmojiReact Announce
|
||||
ChatMessage Answer] do
|
||||
ChatMessage Answer Add Remove] do
|
||||
validator =
|
||||
case type do
|
||||
"Accept" -> AcceptRejectValidator
|
||||
@ -155,6 +155,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
"Announce" -> AnnounceValidator
|
||||
"ChatMessage" -> ChatMessageValidator
|
||||
"Answer" -> AnswerValidator
|
||||
"Add" -> AddRemoveValidator
|
||||
"Remove" -> AddRemoveValidator
|
||||
end
|
||||
|
||||
with {:ok, object} <-
|
||||
@ -166,16 +168,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
end
|
||||
end
|
||||
|
||||
def validate(%{"type" => type} = object, meta) when type in ~w(Add Remove) do
|
||||
with {:ok, object} <-
|
||||
object
|
||||
|> AddRemoveValidator.cast_and_validate()
|
||||
|> Ecto.Changeset.apply_action(:insert) do
|
||||
object = stringify_keys(object)
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
||||
def validate(o, m), do: {:error, {:validator_not_set, {o, m}}}
|
||||
|
||||
def cast_and_apply(%{"type" => "ChatMessage"} = object) do
|
||||
|
Loading…
Reference in New Issue
Block a user