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)
|
def validate(%{"type" => type} = object, meta)
|
||||||
when type in ~w[Accept Reject Follow Update Like EmojiReact Announce
|
when type in ~w[Accept Reject Follow Update Like EmojiReact Announce
|
||||||
ChatMessage Answer] do
|
ChatMessage Answer Add Remove] do
|
||||||
validator =
|
validator =
|
||||||
case type do
|
case type do
|
||||||
"Accept" -> AcceptRejectValidator
|
"Accept" -> AcceptRejectValidator
|
||||||
@ -155,6 +155,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
|||||||
"Announce" -> AnnounceValidator
|
"Announce" -> AnnounceValidator
|
||||||
"ChatMessage" -> ChatMessageValidator
|
"ChatMessage" -> ChatMessageValidator
|
||||||
"Answer" -> AnswerValidator
|
"Answer" -> AnswerValidator
|
||||||
|
"Add" -> AddRemoveValidator
|
||||||
|
"Remove" -> AddRemoveValidator
|
||||||
end
|
end
|
||||||
|
|
||||||
with {:ok, object} <-
|
with {:ok, object} <-
|
||||||
@ -166,16 +168,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
|||||||
end
|
end
|
||||||
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 validate(o, m), do: {:error, {:validator_not_set, {o, m}}}
|
||||||
|
|
||||||
def cast_and_apply(%{"type" => "ChatMessage"} = object) do
|
def cast_and_apply(%{"type" => "ChatMessage"} = object) do
|
||||||
|
Loading…
Reference in New Issue
Block a user