From 3f832e89f610d252e3a144e62200e2e69120b4a2 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 29 Jul 2024 19:27:14 -0400 Subject: [PATCH] Fix topic creation notifications --- lib/philomena/notifications.ex | 24 ++++++++++++++++++------ lib/philomena/notifications/creator.ex | 12 ++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/philomena/notifications.ex b/lib/philomena/notifications.ex index f441c24f..baf2f8be 100644 --- a/lib/philomena/notifications.ex +++ b/lib/philomena/notifications.ex @@ -78,7 +78,13 @@ defmodule Philomena.Notifications do """ def create_channel_live_notification(channel) do - Creator.create_single(ChannelSubscription, ChannelLiveNotification, nil, :channel_id, channel) + Creator.create_single( + where(ChannelSubscription, channel_id: ^channel.id), + ChannelLiveNotification, + nil, + :channel_id, + channel + ) end @doc """ @@ -92,7 +98,7 @@ defmodule Philomena.Notifications do """ def create_forum_post_notification(user, topic, post) do Creator.create_double( - TopicSubscription, + where(TopicSubscription, topic_id: ^topic.id), ForumPostNotification, user, :topic_id, @@ -112,7 +118,13 @@ defmodule Philomena.Notifications do """ def create_forum_topic_notification(user, topic) do - Creator.create_single(ForumSubscription, ForumTopicNotification, user, :topic_id, topic) + Creator.create_single( + where(ForumSubscription, forum_id: ^topic.forum_id), + ForumTopicNotification, + user, + :topic_id, + topic + ) end @doc """ @@ -126,7 +138,7 @@ defmodule Philomena.Notifications do """ def create_gallery_image_notification(gallery) do Creator.create_single( - GallerySubscription, + where(GallerySubscription, gallery_id: ^gallery.id), GalleryImageNotification, nil, :gallery_id, @@ -145,7 +157,7 @@ defmodule Philomena.Notifications do """ def create_image_comment_notification(user, image, comment) do Creator.create_double( - ImageSubscription, + where(ImageSubscription, image_id: ^image.id), ImageCommentNotification, user, :image_id, @@ -166,7 +178,7 @@ defmodule Philomena.Notifications do """ def create_image_merge_notification(target, source) do Creator.create_double( - ImageSubscription, + where(ImageSubscription, image_id: ^target.id), ImageMergeNotification, nil, :target_id, diff --git a/lib/philomena/notifications/creator.ex b/lib/philomena/notifications/creator.ex index 95dd25cd..ee4fec6a 100644 --- a/lib/philomena/notifications/creator.ex +++ b/lib/philomena/notifications/creator.ex @@ -22,7 +22,13 @@ defmodule Philomena.Notifications.Creator do ## Example - iex> create_single(GallerySubscription, GalleryImageNotification, nil, :gallery_id, gallery) + iex> create_single( + ...> where(GallerySubscription, gallery_id: ^gallery.id), + ...> GalleryImageNotification, + ...> nil, + ...> :gallery_id, + ...> gallery + ...> ) {:ok, 2} """ @@ -43,7 +49,7 @@ defmodule Philomena.Notifications.Creator do ## Example iex> create_double( - ...> ImageSubscription, + ...> where(ImageSubscription, image_id: ^image.id), ...> ImageCommentNotification, ...> user, ...> :image_id, @@ -85,7 +91,6 @@ defmodule Philomena.Notifications.Creator do now = DateTime.utc_now(:second) from s in subscription_query(subscription, user), - where: field(s, ^name) == ^object.id, select: %{ ^name => type(^object.id, :integer), user_id: s.user_id, @@ -99,7 +104,6 @@ defmodule Philomena.Notifications.Creator do now = DateTime.utc_now(:second) from s in subscription_query(subscription, user), - where: field(s, ^name1) == ^object1.id, select: %{ ^name1 => type(^object1.id, :integer), ^name2 => type(^object2.id, :integer),