mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
Clear notifications when subscription is removed
This commit is contained in:
parent
c30406bcca
commit
c7f618d9dd
6 changed files with 18 additions and 3 deletions
|
@ -12,6 +12,7 @@ defmodule Philomena.Channels do
|
|||
alias Philomena.Tags
|
||||
|
||||
use Philomena.Subscriptions,
|
||||
on_delete: :clear_channel_notification,
|
||||
id_name: :channel_id
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -19,6 +19,7 @@ defmodule Philomena.Galleries do
|
|||
alias Philomena.Images
|
||||
|
||||
use Philomena.Subscriptions,
|
||||
on_delete: :clear_gallery_notification,
|
||||
id_name: :gallery_id
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -39,6 +39,7 @@ defmodule Philomena.Images do
|
|||
alias Philomena.Users.User
|
||||
|
||||
use Philomena.Subscriptions,
|
||||
on_delete: :clear_image_notification,
|
||||
id_name: :image_id
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -25,6 +25,18 @@ defmodule Philomena.Subscriptions do
|
|||
# For Philomena.Images, this yields :image_id
|
||||
field_name = Keyword.fetch!(opts, :id_name)
|
||||
|
||||
# Deletion callback
|
||||
on_delete =
|
||||
case Keyword.get(opts, :on_delete) do
|
||||
nil ->
|
||||
[]
|
||||
|
||||
callback when is_atom(callback) ->
|
||||
quote do
|
||||
apply(__MODULE__, unquote(callback), [object, user])
|
||||
end
|
||||
end
|
||||
|
||||
# For Philomena.Images, this yields Philomena.Images.Subscription
|
||||
subscription_module = Module.concat(__CALLER__.module, Subscription)
|
||||
|
||||
|
@ -100,6 +112,8 @@ defmodule Philomena.Subscriptions do
|
|||
|
||||
"""
|
||||
def delete_subscription(object, user) do
|
||||
unquote(on_delete)
|
||||
|
||||
Philomena.Subscriptions.delete_subscription(
|
||||
unquote(subscription_module),
|
||||
unquote(field_name),
|
||||
|
|
|
@ -14,6 +14,7 @@ defmodule Philomena.Topics do
|
|||
alias Philomena.NotificationWorker
|
||||
|
||||
use Philomena.Subscriptions,
|
||||
on_delete: :clear_topic_notification,
|
||||
id_name: :topic_id
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -18,6 +18,3 @@
|
|||
.flex.flex--centered.flex--no-wrap
|
||||
a.button.button--separate-right title="Delete" href=~p"/forums/#{forum}/topics/#{topic}/read" data-method="post" data-remote="true" data-click-hideparent=".notification"
|
||||
i.fa.fa-trash
|
||||
|
||||
a.button title="Unsubscribe" href=~p"/forums/#{forum}/subscription" data-method="delete" data-remote="true" data-click-hideparent=".notification"
|
||||
i.fa.fa-bell-slash
|
||||
|
|
Loading…
Reference in a new issue