@impl true
def filter(activity) do
activity =
- if activity["type"] == "Create" && local?(activity) do
+ if note?(activity) and local?(activity) do
maybe_add_expiration(activity)
else
activity
String.starts_with?(id, Pleroma.Web.Endpoint.url())
end
+ defp note?(activity) do
+ match?(%{"type" => "Create", "object" => %{"type" => "Note"}}, activity)
+ end
+
defp maybe_add_expiration(activity) do
days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: days)
test "adds `expires_at` property" do
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
- ActivityExpirationPolicy.filter(%{"id" => @id, "type" => "Create"})
+ ActivityExpirationPolicy.filter(%{
+ "id" => @id,
+ "type" => "Create",
+ "object" => %{"type" => "Note"}
+ })
assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
end
ActivityExpirationPolicy.filter(%{
"id" => @id,
"type" => "Create",
- "expires_at" => expires_at
+ "expires_at" => expires_at,
+ "object" => %{"type" => "Note"}
})
end
ActivityExpirationPolicy.filter(%{
"id" => @id,
"type" => "Create",
- "expires_at" => too_distant_future
+ "expires_at" => too_distant_future,
+ "object" => %{"type" => "Note"}
})
assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
assert {:ok, activity} =
ActivityExpirationPolicy.filter(%{
"id" => "https://example.com/123",
- "type" => "Create"
+ "type" => "Create",
+ "object" => %{"type" => "Note"}
})
refute Map.has_key?(activity, "expires_at")
end
- test "ignores non-Create activities" do
+ test "ignores non-Create/Note activities" do
assert {:ok, activity} =
ActivityExpirationPolicy.filter(%{
"id" => "https://example.com/123",
})
refute Map.has_key?(activity, "expires_at")
+
+ assert {:ok, activity} =
+ ActivityExpirationPolicy.filter(%{
+ "id" => "https://example.com/123",
+ "type" => "Create",
+ "object" => %{"type" => "Cofe"}
+ })
+
+ refute Map.has_key?(activity, "expires_at")
end
end