Fix topic creation notifications

This commit is contained in:
Liam 2024-07-29 19:27:14 -04:00
parent 3d69807118
commit 3f832e89f6
2 changed files with 26 additions and 10 deletions

View file

@ -78,7 +78,13 @@ defmodule Philomena.Notifications do
""" """
def create_channel_live_notification(channel) 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 end
@doc """ @doc """
@ -92,7 +98,7 @@ defmodule Philomena.Notifications do
""" """
def create_forum_post_notification(user, topic, post) do def create_forum_post_notification(user, topic, post) do
Creator.create_double( Creator.create_double(
TopicSubscription, where(TopicSubscription, topic_id: ^topic.id),
ForumPostNotification, ForumPostNotification,
user, user,
:topic_id, :topic_id,
@ -112,7 +118,13 @@ defmodule Philomena.Notifications do
""" """
def create_forum_topic_notification(user, topic) 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 end
@doc """ @doc """
@ -126,7 +138,7 @@ defmodule Philomena.Notifications do
""" """
def create_gallery_image_notification(gallery) do def create_gallery_image_notification(gallery) do
Creator.create_single( Creator.create_single(
GallerySubscription, where(GallerySubscription, gallery_id: ^gallery.id),
GalleryImageNotification, GalleryImageNotification,
nil, nil,
:gallery_id, :gallery_id,
@ -145,7 +157,7 @@ defmodule Philomena.Notifications do
""" """
def create_image_comment_notification(user, image, comment) do def create_image_comment_notification(user, image, comment) do
Creator.create_double( Creator.create_double(
ImageSubscription, where(ImageSubscription, image_id: ^image.id),
ImageCommentNotification, ImageCommentNotification,
user, user,
:image_id, :image_id,
@ -166,7 +178,7 @@ defmodule Philomena.Notifications do
""" """
def create_image_merge_notification(target, source) do def create_image_merge_notification(target, source) do
Creator.create_double( Creator.create_double(
ImageSubscription, where(ImageSubscription, image_id: ^target.id),
ImageMergeNotification, ImageMergeNotification,
nil, nil,
:target_id, :target_id,

View file

@ -22,7 +22,13 @@ defmodule Philomena.Notifications.Creator do
## Example ## 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} {:ok, 2}
""" """
@ -43,7 +49,7 @@ defmodule Philomena.Notifications.Creator do
## Example ## Example
iex> create_double( iex> create_double(
...> ImageSubscription, ...> where(ImageSubscription, image_id: ^image.id),
...> ImageCommentNotification, ...> ImageCommentNotification,
...> user, ...> user,
...> :image_id, ...> :image_id,
@ -85,7 +91,6 @@ defmodule Philomena.Notifications.Creator do
now = DateTime.utc_now(:second) now = DateTime.utc_now(:second)
from s in subscription_query(subscription, user), from s in subscription_query(subscription, user),
where: field(s, ^name) == ^object.id,
select: %{ select: %{
^name => type(^object.id, :integer), ^name => type(^object.id, :integer),
user_id: s.user_id, user_id: s.user_id,
@ -99,7 +104,6 @@ defmodule Philomena.Notifications.Creator do
now = DateTime.utc_now(:second) now = DateTime.utc_now(:second)
from s in subscription_query(subscription, user), from s in subscription_query(subscription, user),
where: field(s, ^name1) == ^object1.id,
select: %{ select: %{
^name1 => type(^object1.id, :integer), ^name1 => type(^object1.id, :integer),
^name2 => type(^object2.id, :integer), ^name2 => type(^object2.id, :integer),