Move tag fixup to object_validator
This commit is contained in:
parent
7ebfe89900
commit
ef36f7fa5c
@ -114,8 +114,33 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
end
|
||||
|
||||
def validate(%{"type" => type} = object, meta)
|
||||
when type in ~w[Event Question Audio Video Article] do
|
||||
validator =
|
||||
case type do
|
||||
"Event" -> EventValidator
|
||||
"Question" -> QuestionValidator
|
||||
"Audio" -> AudioVideoValidator
|
||||
"Video" -> AudioVideoValidator
|
||||
"Article" -> ArticleNoteValidator
|
||||
end
|
||||
|
||||
with {:ok, object} <-
|
||||
object
|
||||
|> validator.cast_and_validate()
|
||||
|> Ecto.Changeset.apply_action(:insert) do
|
||||
object = stringify_keys(object)
|
||||
|
||||
# Insert copy of hashtags as strings for the non-hashtag table indexing
|
||||
tag = (object["tag"] || []) ++ Object.hashtags(%Object{data: object})
|
||||
object = Map.put(object, "tag", tag)
|
||||
|
||||
{:ok, object, meta}
|
||||
end
|
||||
end
|
||||
|
||||
def validate(%{"type" => type} = object, meta)
|
||||
when type in ~w[Accept Reject Follow Update Like EmojiReact Announce
|
||||
Event ChatMessage Question Audio Video Article Answer] do
|
||||
ChatMessage Answer] do
|
||||
validator =
|
||||
case type do
|
||||
"Accept" -> AcceptRejectValidator
|
||||
@ -125,12 +150,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
|
||||
"Like" -> LikeValidator
|
||||
"EmojiReact" -> EmojiReactValidator
|
||||
"Announce" -> AnnounceValidator
|
||||
"Event" -> EventValidator
|
||||
"ChatMessage" -> ChatMessageValidator
|
||||
"Question" -> QuestionValidator
|
||||
"Audio" -> AudioVideoValidator
|
||||
"Video" -> AudioVideoValidator
|
||||
"Article" -> ArticleNoteValidator
|
||||
"Answer" -> AnswerValidator
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,6 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
|
||||
def do_common_pipeline(message, meta) do
|
||||
with {_, {:ok, message, meta}} <- {:validate, @object_validator.validate(message, meta)},
|
||||
{_, {:ok, message, meta}} <- {:fixup, validation_fixups(message, meta)},
|
||||
{_, {:ok, message, meta}} <- {:mrf, @mrf.pipeline_filter(message, meta)},
|
||||
{_, {:ok, message, meta}} <- {:persist, @activity_pub.persist(message, meta)},
|
||||
{_, {:ok, message, meta}} <- {:side_effects, @side_effects.handle(message, meta)},
|
||||
@ -56,19 +55,6 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||
end
|
||||
end
|
||||
|
||||
defp validation_fixups(message, meta) do
|
||||
# Insert copy of hashtags as strings for the non-hashtag table indexing
|
||||
message =
|
||||
if message["tag"] do
|
||||
tag = Object.hashtags(%Object{data: message}) ++ (message["tag"] || [])
|
||||
Map.put(message, "tag", tag)
|
||||
else
|
||||
message
|
||||
end
|
||||
|
||||
{:ok, message, meta}
|
||||
end
|
||||
|
||||
defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
|
||||
|
||||
defp maybe_federate(%Activity{} = activity, meta) do
|
||||
|
Loading…
Reference in New Issue
Block a user