From e0dc9c79f237112d0c84318371e9b20e39528244 Mon Sep 17 00:00:00 2001 From: liamwhite Date: Wed, 10 May 2023 21:42:56 -0400 Subject: [PATCH] fix gallery notification deletion (#183) --- lib/philomena/galleries.ex | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/philomena/galleries.ex b/lib/philomena/galleries.ex index 3119e3d2..2b08e3e1 100644 --- a/lib/philomena/galleries.ex +++ b/lib/philomena/galleries.ex @@ -15,6 +15,7 @@ defmodule Philomena.Galleries do alias Philomena.GalleryReorderWorker alias Philomena.Notifications alias Philomena.NotificationWorker + alias Philomena.Notifications.{Notification, UnreadNotification} alias Philomena.Images @doc """ @@ -90,9 +91,24 @@ defmodule Philomena.Galleries do |> select([i], i.image_id) |> Repo.all() - Repo.delete(gallery) + unread_notifications = + UnreadNotification + |> join(:inner, [un], _ in assoc(un, :notification)) + |> where([_, n], n.actor_type == "Gallery") + |> where([_, n], n.actor_id == ^gallery.id) + + notifications = + Notification + |> where(actor_type: "Gallery") + |> where(actor_id: ^gallery.id) + + Multi.new() + |> Multi.delete(:gallery, gallery) + |> Multi.delete_all(:unread_notifications, unread_notifications) + |> Multi.delete_all(:notifications, notifications) + |> Repo.transaction() |> case do - {:ok, gallery} -> + {:ok, %{gallery: gallery}} -> unindex_gallery(gallery) Images.reindex_images(images)