From 5db190d6b84762437b6ffe9699927626daba4900 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 1 Dec 2019 00:03:45 -0500 Subject: [PATCH] automatic notifications clearing --- lib/philomena/forums.ex | 1 + lib/philomena/images.ex | 1 + lib/philomena/topics.ex | 1 + lib/philomena_web/controllers/image_controller.ex | 3 +++ lib/philomena_web/controllers/topic_controller.ex | 7 ++++++- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/philomena/forums.ex b/lib/philomena/forums.ex index e5dc83b9..009be8f8 100644 --- a/lib/philomena/forums.ex +++ b/lib/philomena/forums.ex @@ -137,6 +137,7 @@ defmodule Philomena.Forums do |> Repo.delete() end + def clear_notification(_forum, nil), do: nil def clear_notification(forum, user) do Notifications.delete_unread_notification("Forum", forum.id, user) end diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 2cb68337..5c967217 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -290,6 +290,7 @@ defmodule Philomena.Images do |> Repo.delete() end + def clear_notification(_image, nil), do: nil def clear_notification(image, user) do Notifications.delete_unread_notification("Image", image.id, user) end diff --git a/lib/philomena/topics.ex b/lib/philomena/topics.ex index f65f50e8..290c9efd 100644 --- a/lib/philomena/topics.ex +++ b/lib/philomena/topics.ex @@ -190,6 +190,7 @@ defmodule Philomena.Topics do |> Repo.delete() end + def clear_notification(_topic, nil), do: nil def clear_notification(topic, user) do Notifications.delete_unread_notification("Topic", topic.id, user) end diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 60565467..ee183cf2 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -29,6 +29,9 @@ defmodule PhilomenaWeb.ImageController do def show(conn, %{"id" => _id}) do image = conn.assigns.image + user = conn.assigns.current_user + + Images.clear_notification(image, user) comments = Comment diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index 6d837341..783ed125 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.TopicController do use PhilomenaWeb, :controller alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption} - alias Philomena.{Topics, Posts} + alias Philomena.{Forums, Topics, Posts} alias Philomena.Textile.Renderer alias Philomena.Repo import Ecto.Query @@ -22,6 +22,11 @@ defmodule PhilomenaWeb.TopicController do |> preload([:user, poll: :options]) |> Repo.one() + user = conn.assigns.current_user + + Topics.clear_notification(topic, user) + Forums.clear_notification(forum, user) + conn = conn |> assign(:topic, topic) %{page_number: page} = conn.assigns.pagination