alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
- alias Pleroma.Web.ActivityPub.Utils
import Ecto.Changeset
@primary_key false
@derive Jason.Encoder
- # Extends from NoteValidator
embedded_schema do
field(:id, ObjectValidators.ObjectID, primary_key: true)
field(:to, ObjectValidators.Recipients, default: [])
|> changeset(data)
end
- # based on Pleroma.Web.ActivityPub.Utils.lazy_put_objects_defaults
- defp fix_defaults(data) do
- %{data: %{"id" => context}, id: context_id} =
- Utils.create_context(data["context"] || data["conversation"])
-
- data
- |> Map.put_new_lazy("published", &Utils.make_date/0)
- |> Map.put_new("context", context)
- |> Map.put_new("context_id", context_id)
- end
-
- defp fix_attribution(data) do
- data
- |> Map.put_new("actor", data["attributedTo"])
- end
-
defp fix(data) do
data
- |> fix_defaults()
- |> fix_attribution()
+ |> CommonFixes.fix_defaults()
+ |> CommonFixes.fix_attribution()
end
def changeset(struct, data) do
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
+ alias Pleroma.Web.ActivityPub.Utils
+
+ # based on Pleroma.Web.ActivityPub.Utils.lazy_put_objects_defaults
+ def fix_defaults(data) do
+ %{data: %{"id" => context}, id: context_id} =
+ Utils.create_context(data["context"] || data["conversation"])
+
+ data
+ |> Map.put_new_lazy("published", &Utils.make_date/0)
+ |> Map.put_new("context", context)
+ |> Map.put_new("context_id", context_id)
+ end
+
+ def fix_attribution(data) do
+ data
+ |> Map.put_new("actor", data["attributedTo"])
+ end
+end
alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
+ alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
alias Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator
- alias Pleroma.Web.ActivityPub.Utils
import Ecto.Changeset
end
end
- # based on Pleroma.Web.ActivityPub.Utils.lazy_put_objects_defaults
- defp fix_defaults(data) do
- %{data: %{"id" => context}, id: context_id} =
- Utils.create_context(data["context"] || data["conversation"])
-
- data
- |> Map.put_new_lazy("published", &Utils.make_date/0)
- |> Map.put_new("context", context)
- |> Map.put_new("context_id", context_id)
- end
-
- defp fix_attribution(data) do
- data
- |> Map.put_new("actor", data["attributedTo"])
- end
-
defp fix(data) do
data
- |> fix_attribution()
+ |> CommonFixes.fix_defaults()
+ |> CommonFixes.fix_attribution()
|> fix_closed()
- |> fix_defaults()
end
def changeset(struct, data) do