Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Jul 30, 2024
2 parents 1b8edd2 + 0891fe3 commit 48d672d
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions lib/philomena/images.ex
Original file line number Diff line number Diff line change
Expand Up @@ -935,15 +935,38 @@ defmodule Philomena.Images do

Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing)

comment_notifications =
from cn in ImageCommentNotification,
where: cn.image_id == ^source.id,
select: %{
user_id: cn.user_id,
image_id: ^target.id,
comment_id: cn.comment_id,
read: cn.read,
created_at: cn.created_at,
updated_at: cn.updated_at
}

merge_notifications =
from mn in ImageMergeNotification,
where: mn.target_id == ^source.id,
select: %{
user_id: mn.user_id,
target_id: ^target.id,
source_id: mn.source_id,
read: mn.read,
created_at: mn.created_at,
updated_at: mn.updated_at
}

{comment_notification_count, nil} =
ImageCommentNotification
|> where(image_id: ^source.id)
|> Repo.update_all(set: [image_id: target.id])
Repo.insert_all(ImageCommentNotification, comment_notifications, on_conflict: :nothing)

{merge_notification_count, nil} =
ImageMergeNotification
|> where(target_id: ^source.id)
|> Repo.update_all(set: [target_id: target.id])
Repo.insert_all(ImageMergeNotification, merge_notifications, on_conflict: :nothing)

Repo.delete_all(exclude(comment_notifications, :select))
Repo.delete_all(exclude(merge_notifications, :select))

{:ok, {comment_notification_count, merge_notification_count}}
end
Expand Down

0 comments on commit 48d672d

Please sign in to comment.