diff --git a/lib/philomena/channels.ex b/lib/philomena/channels.ex index 2ffd4ce4..efa6d47c 100644 --- a/lib/philomena/channels.ex +++ b/lib/philomena/channels.ex @@ -12,6 +12,7 @@ defmodule Philomena.Channels do alias Philomena.Tags use Philomena.Subscriptions, + on_delete: :clear_channel_notification, id_name: :channel_id @doc """ diff --git a/lib/philomena/galleries.ex b/lib/philomena/galleries.ex index 4c76df35..c553ad3e 100644 --- a/lib/philomena/galleries.ex +++ b/lib/philomena/galleries.ex @@ -19,6 +19,7 @@ defmodule Philomena.Galleries do alias Philomena.Images use Philomena.Subscriptions, + on_delete: :clear_gallery_notification, id_name: :gallery_id @doc """ diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 92c02155..4ebc215a 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -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 """ diff --git a/lib/philomena/subscriptions.ex b/lib/philomena/subscriptions.ex index 8e67183f..d0688107 100644 --- a/lib/philomena/subscriptions.ex +++ b/lib/philomena/subscriptions.ex @@ -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), diff --git a/lib/philomena/topics.ex b/lib/philomena/topics.ex index 02524ea3..e1e5af29 100644 --- a/lib/philomena/topics.ex +++ b/lib/philomena/topics.ex @@ -14,6 +14,7 @@ defmodule Philomena.Topics do alias Philomena.NotificationWorker use Philomena.Subscriptions, + on_delete: :clear_topic_notification, id_name: :topic_id @doc """ diff --git a/lib/philomena_web/templates/notification/_topic.html.slime b/lib/philomena_web/templates/notification/_topic.html.slime index ff84ca3e..37f6786d 100644 --- a/lib/philomena_web/templates/notification/_topic.html.slime +++ b/lib/philomena_web/templates/notification/_topic.html.slime @@ -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