diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex index 3e68bcad60..3e589eed2a 100644 --- a/lib/pleroma/web/common_api/activity_draft.ex +++ b/lib/pleroma/web/common_api/activity_draft.ex @@ -128,7 +128,13 @@ defp attachments(%{params: params} = draft) do defp in_reply_to(%{params: %{in_reply_to_status_id: ""}} = draft), do: draft defp in_reply_to(%{params: %{in_reply_to_status_id: id}} = draft) when is_binary(id) do - %__MODULE__{draft | in_reply_to: Activity.get_by_id(id)} + case Activity.get_by_id(id) do + %Activity{} = activity -> + %__MODULE__{draft | in_reply_to: activity} + + _ -> + add_error(draft, dgettext("errors", "The post being replied to was deleted")) + end end defp in_reply_to(%{params: %{in_reply_to_status_id: %Activity{} = in_reply_to}} = draft) do diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 2a6467608d..1e4554a66f 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -1045,23 +1045,6 @@ test "repeating an activity which is already deleted does not generate a notific assert Enum.empty?(Notification.for_user(user)) end - test "replying to a deleted post without tagging does not generate a notification" do - user = insert(:user) - other_user = insert(:user) - - {:ok, activity} = CommonAPI.post(user, %{status: "test post"}) - {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user) - - {:ok, _reply_activity} = - CommonAPI.post(other_user, %{ - status: "test reply", - in_reply_to_status_id: activity.id - }) - - Pleroma.Tests.ObanHelpers.perform_all() - assert Enum.empty?(Notification.for_user(user)) - end - test "notifications are deleted if a local user is deleted" do user = insert(:user) other_user = insert(:user) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index fbd752fa34..d445233ce3 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -773,6 +773,13 @@ test "quote posting visibility" do {:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: unlisted.id}) {:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id}) end + + test "block replying to a deleted or non-existant status" do + user = insert(:user) + + assert {:error, "The post being replied to was deleted"} = + CommonAPI.post(user, %{status: "hi", in_reply_to_id: "nonexistant"}) + end end describe "reactions" do