From 0a2c1fef16f8a90ce793f5d6bcf5bfb9bc12917f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 13 Aug 2023 18:38:52 +0200 Subject: [PATCH] store published date for new activities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/object/fetcher.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 12 +++++++++++- .../object_validators/create_generic_validator.ex | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) 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