diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index af5642af43..27f11a07c1 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -121,7 +121,8 @@ defp prepare_activity_params(data) do "type" => "Create", # Should we seriously keep this attributedTo thing? "actor" => data["actor"] || data["attributedTo"], - "object" => data + "object" => data, + "published" => data["published"] } |> Maps.put_if_present("to", data["to"]) |> Maps.put_if_present("cc", data["cc"]) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index f9c837b507..a727f21066 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -137,7 +137,8 @@ def persist(object, meta) do data: object, local: local, recipients: recipients, - actor: object["actor"] + actor: object["actor"], + published_at: get_published_at(object) }), # TODO: add tests for expired activities, when Note type will be supported in new pipeline {:ok, _} <- maybe_create_activity_expiration(activity) do @@ -145,6 +146,15 @@ def persist(object, meta) do end end + defp get_published_at(object) do + with date <- Map.get(object, "published", NaiveDateTime.utc_now()), + {:ok, casted_date} <- Ecto.Type.cast(:naive_datetime, date) do + casted_date + else + _ -> nil + end + end + @spec insert(map(), boolean(), boolean(), boolean()) :: {:ok, Activity.t()} | {:error, any()} def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when is_map(map) do with nil <- Activity.normalize(map), diff --git a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex index 201abe3db0..701702beaf 100644 --- a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex @@ -28,6 +28,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do end end + field(:published, ObjectValidators.DateTime) field(:expires_at, ObjectValidators.DateTime) # Should be moved to object, done for CommonAPI.Utils.make_context