diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs index 5fbd8660d..8f48d02de 100644 --- a/test/mix/tasks/pleroma/database_test.exs +++ b/test/mix/tasks/pleroma/database_test.exs @@ -200,21 +200,33 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do refute Object.get_by_ap_id(old_remote_post2_id) end - test "with the --keep-threads option it keeps old threads that mentioned a local user", %{ + test "with the --keep-threads option it keeps old threads addressed to a local user", %{ old_insert_date: old_insert_date } do remote_user = insert(:user, local: false) local_user = insert(:user) - {:ok, activity} = CommonAPI.post(remote_user, %{status: "hey @#{local_user.nickname}"}) + {:ok, mention} = CommonAPI.post(remote_user, %{status: "hey @#{local_user.nickname}"}) - activity - |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) - |> Repo.update!() + {:ok, dm} = + CommonAPI.post(remote_user, %{ + status: "psst @#{local_user.nickname}", + visibility: "direct" + }) + + # The pin must not depend on the notifications still being there + Pleroma.Notification.clear(local_user) + + for activity <- [mention, dm] do + activity + |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) + |> Repo.update!() + end Mix.Tasks.Pleroma.Database.run(["prune_objects", "--keep-threads"]) - assert Object.get_by_ap_id(activity.data["object"]) + assert Object.get_by_ap_id(mention.data["object"]) + assert Object.get_by_ap_id(dm.data["object"]) end test "with the --keep-threads option it still keeps non-old threads even with no local interactions" do diff --git a/test/pleroma/retention_test.exs b/test/pleroma/retention_test.exs index 43c77704a..ccb40cb69 100644 --- a/test/pleroma/retention_test.exs +++ b/test/pleroma/retention_test.exs @@ -265,6 +265,20 @@ defmodule Pleroma.RetentionTest do assert Object.get_by_ap_id(post.data["object"]) end + test "keeps an old thread with a recent reply, even over the watermark", %{ + old_date: old_date + } do + clear_config([:retention, :max_objects], 0) + remote_user = insert(:user, local: false) + + {:ok, post} = CommonAPI.post(remote_user, %{status: "old but active"}) + # Old id, so the walk reaches it, but active an hour ago + age(post, old_date, %{local: false, updated_at: NaiveDateTime.add(days_ago(0), -3_600)}) + + assert %{contexts: 0} = Retention.run() + assert Object.get_by_ap_id(post.data["object"]) + end + test "does not evict anything below the watermark" do clear_config([:retention, :max_objects], 100) remote_user = insert(:user, local: false)