store published date for new activities

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-08-13 18:38:52 +02:00
parent 06e2225bf4
commit 0a2c1fef16
3 changed files with 14 additions and 2 deletions

View file

@ -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"])

View file

@ -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),

View file

@ -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