expiration for new pipeline

This commit is contained in:
Alexander Strizhakov 2020-09-03 17:56:20 +03:00 committed by rinpatch
parent 93e1c8df9d
commit 357d971a10
2 changed files with 12 additions and 13 deletions

View file

@ -101,7 +101,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
local: local, local: local,
recipients: recipients, recipients: recipients,
actor: object["actor"] actor: object["actor"]
}) do }),
# TODO: add tests for expired activities, when Note type will be supported in new pipeline
{:ok, _} <- maybe_create_activity_expiration(activity) do
{:ok, activity, meta} {:ok, activity, meta}
end end
end end
@ -158,14 +160,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end end
defp insert_activity_with_expiration(data, local, recipients) do defp insert_activity_with_expiration(data, local, recipients) do
%Activity{ struct = %Activity{
data: data, data: data,
local: local, local: local,
actor: data["actor"], actor: data["actor"],
recipients: recipients recipients: recipients
} }
|> Repo.insert()
|> maybe_create_activity_expiration() with {:ok, activity} <- Repo.insert(struct) do
maybe_create_activity_expiration(activity)
end
end end
def notify_and_stream(activity) do def notify_and_stream(activity) do
@ -177,7 +181,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
stream_out_participations(participations) stream_out_participations(participations)
end end
defp maybe_create_activity_expiration({:ok, %{data: %{"expires_at" => expires_at}} = activity}) do defp maybe_create_activity_expiration(
%{data: %{"expires_at" => %DateTime{} = expires_at}} = activity
) do
with {:ok, _job} <- with {:ok, _job} <-
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{ Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
activity_id: activity.id, activity_id: activity.id,
@ -187,7 +193,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end end
end end
defp maybe_create_activity_expiration(result), do: result defp maybe_create_activity_expiration(activity), do: {:ok, activity}
defp create_or_bump_conversation(activity, actor) do defp create_or_bump_conversation(activity, actor) do
with {:ok, conversation} <- Conversation.create_or_bump_for(activity), with {:ok, conversation} <- Conversation.create_or_bump_for(activity),

View file

@ -187,13 +187,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
Object.increase_replies_count(in_reply_to) Object.increase_replies_count(in_reply_to)
end end
if expires_at = activity.data["expires_at"] do
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
activity_id: activity.id,
expires_at: expires_at
})
end
BackgroundWorker.enqueue("fetch_data_for_activity", %{"activity_id" => activity.id}) BackgroundWorker.enqueue("fetch_data_for_activity", %{"activity_id" => activity.id})
meta = meta =