1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy do
6 @moduledoc "Adds expiration to all local Create activities"
7 @behaviour Pleroma.Web.ActivityPub.MRF
10 def filter(activity) do
12 if activity["type"] == "Create" && local?(activity) do
13 maybe_add_expiration(activity)
22 def describe, do: {:ok, %{}}
24 defp local?(%{"id" => id}) do
25 String.starts_with?(id, Pleroma.Web.Endpoint.url())
28 defp maybe_add_expiration(activity) do
29 days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
30 expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: days)
32 with %{"expires_at" => existing_expires_at} <- activity,
33 :lt <- NaiveDateTime.compare(existing_expires_at, expires_at) do
36 _ -> Map.put(activity, "expires_at", expires_at)