end
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
"Like" -> LikeValidator
"EmojiReact" -> EmojiReactValidator
"Announce" -> AnnounceValidator
- "Event" -> EventValidator
"ChatMessage" -> ChatMessageValidator
- "Question" -> QuestionValidator
- "Audio" -> AudioVideoValidator
- "Video" -> AudioVideoValidator
- "Article" -> ArticleNoteValidator
"Answer" -> AnswerValidator
end
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)},
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