1 # Pleroma: A lightweight social networking server
2 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Daemons.ActivityExpirationDaemon do
7 alias Pleroma.ActivityExpiration
11 alias Pleroma.Web.CommonAPI
17 @schedule_interval :timer.minutes(1)
20 GenServer.start_link(__MODULE__, nil)
25 if Config.get([ActivityExpiration, :enabled]) do
33 def perform(:execute, expiration_id) do
37 |> where([e], e.id == ^expiration_id)
40 activity = Activity.get_by_id_with_object(expiration.activity_id)
41 user = User.get_by_ap_id(activity.object.data["actor"])
42 CommonAPI.delete(activity.id, user)
45 Logger.error("#{__MODULE__} Couldn't delete expired activity: #{inspect(error)}")
50 def handle_info(:perform, state) do
51 ActivityExpiration.due_expirations(@schedule_interval)
52 |> Enum.each(fn expiration ->
53 Pleroma.Workers.ActivityExpirationWorker.enqueue(
54 "activity_expiration",
55 %{"activity_expiration_id" => expiration.id}
64 Process.send_after(self(), :perform, @schedule_interval)