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 29, 2024
2 parents e5fe3ce + fe59b04 commit 307f59e
Show file tree
Hide file tree
Showing 47 changed files with 1,283 additions and 554 deletions.
16 changes: 15 additions & 1 deletion lib/philomena/channels.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ defmodule Philomena.Channels do

alias Philomena.Channels.AutomaticUpdater
alias Philomena.Channels.Channel
alias Philomena.Notifications
alias Philomena.Tags

use Philomena.Subscriptions,
actor_types: ~w(Channel LivestreamChannel),
id_name: :channel_id

@doc """
Expand Down Expand Up @@ -139,4 +139,18 @@ defmodule Philomena.Channels do
def change_channel(%Channel{} = channel) do
Channel.changeset(channel, %{})
end

@doc """
Removes all channel notifications for a given channel and user.
## Examples
iex> clear_channel_notification(channel, user)
:ok
"""
def clear_channel_notification(%Channel{} = channel, user) do
Notifications.clear_channel_live_notification(channel, user)
:ok
end
end
17 changes: 1 addition & 16 deletions lib/philomena/comments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,7 @@ defmodule Philomena.Comments do
|> Repo.preload(:image)
|> Map.fetch!(:image)

subscriptions =
image
|> Repo.preload(:subscriptions)
|> Map.fetch!(:subscriptions)

Notifications.notify(
comment,
subscriptions,
%{
actor_id: image.id,
actor_type: "Image",
actor_child_id: comment.id,
actor_child_type: "Comment",
action: "commented on"
}
)
Notifications.create_image_comment_notification(image, comment)
end

@doc """
Expand Down
1 change: 0 additions & 1 deletion lib/philomena/forums.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ defmodule Philomena.Forums do
alias Philomena.Forums.Forum

use Philomena.Subscriptions,
actor_types: ~w(Forum),
id_name: :forum_id

@doc """
Expand Down
34 changes: 16 additions & 18 deletions lib/philomena/galleries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defmodule Philomena.Galleries do
alias Philomena.Images

use Philomena.Subscriptions,
actor_types: ~w(Gallery),
id_name: :gallery_id

@doc """
Expand Down Expand Up @@ -269,25 +268,10 @@ defmodule Philomena.Galleries do
Exq.enqueue(Exq, "notifications", NotificationWorker, ["Galleries", [gallery.id, image.id]])
end

def perform_notify([gallery_id, image_id]) do
def perform_notify([gallery_id, _image_id]) do
gallery = get_gallery!(gallery_id)

subscriptions =
gallery
|> Repo.preload(:subscriptions)
|> Map.fetch!(:subscriptions)

Notifications.notify(
gallery,
subscriptions,
%{
actor_id: gallery.id,
actor_type: "Gallery",
actor_child_id: image_id,
actor_child_type: "Image",
action: "added images to"
}
)
Notifications.create_gallery_image_notification(gallery)
end

def reorder_gallery(gallery, image_ids) do
Expand Down Expand Up @@ -360,4 +344,18 @@ defmodule Philomena.Galleries do

defp position_order(%{order_position_asc: true}), do: [asc: :position]
defp position_order(_gallery), do: [desc: :position]

@doc """
Removes all gallery notifications for a given gallery and user.
## Examples
iex> clear_gallery_notification(gallery, user)
:ok
"""
def clear_gallery_notification(%Gallery{} = gallery, user) do
Notifications.clear_gallery_image_notification(gallery, user)
:ok
end
end
52 changes: 29 additions & 23 deletions lib/philomena/images.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ defmodule Philomena.Images do
alias Philomena.IndexWorker
alias Philomena.ImageFeatures.ImageFeature
alias Philomena.SourceChanges.SourceChange
alias Philomena.Notifications.Notification
alias Philomena.Notifications.ImageCommentNotification
alias Philomena.Notifications.ImageMergeNotification
alias Philomena.NotificationWorker
alias Philomena.TagChanges.Limits
alias Philomena.TagChanges.TagChange
Expand All @@ -39,7 +40,6 @@ defmodule Philomena.Images do
alias Philomena.Games.{Player, Team}

use Philomena.Subscriptions,
actor_types: ~w(Image),
id_name: :image_id

@doc """
Expand Down Expand Up @@ -934,12 +934,17 @@ defmodule Philomena.Images do

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

{count, nil} =
Notification
|> where(actor_type: "Image", actor_id: ^source.id)
|> Repo.delete_all()
{comment_notification_count, nil} =
ImageCommentNotification
|> where(image_id: ^source.id)
|> Repo.update_all(set: [image_id: target.id])

{merge_notification_count, nil} =
ImageMergeNotification
|> where(image_id: ^source.id)
|> Repo.update_all(set: [image_id: target.id])

{:ok, count}
{:ok, {comment_notification_count, merge_notification_count}}
end

def migrate_sources(source, target) do
Expand All @@ -959,23 +964,24 @@ defmodule Philomena.Images do
end

def perform_notify([source_id, target_id]) do
source = get_image!(source_id)
target = get_image!(target_id)

subscriptions =
target
|> Repo.preload(:subscriptions)
|> Map.fetch!(:subscriptions)

Notifications.notify(
nil,
subscriptions,
%{
actor_id: target.id,
actor_type: "Image",
actor_child_id: nil,
actor_child_type: nil,
action: "merged ##{source_id} into"
}
)
Notifications.create_image_merge_notification(target, source)
end

@doc """
Removes all image notifications for a given image and user.
## Examples
iex> clear_image_notification(image, user)
:ok
"""
def clear_image_notification(%Image{} = image, user) do
Notifications.clear_image_comment_notification(image, user)
Notifications.clear_image_merge_notification(image, user)
:ok
end
end
Loading

0 comments on commit 307f59e

Please sign in to comment.