automatic notifications clearing

This commit is contained in:
byte[] 2019-12-01 00:03:45 -05:00
parent 80077786cf
commit 5db190d6b8
5 changed files with 12 additions and 1 deletions

View file

@ -137,6 +137,7 @@ defmodule Philomena.Forums do
|> Repo.delete() |> Repo.delete()
end end
def clear_notification(_forum, nil), do: nil
def clear_notification(forum, user) do def clear_notification(forum, user) do
Notifications.delete_unread_notification("Forum", forum.id, user) Notifications.delete_unread_notification("Forum", forum.id, user)
end end

View file

@ -290,6 +290,7 @@ defmodule Philomena.Images do
|> Repo.delete() |> Repo.delete()
end end
def clear_notification(_image, nil), do: nil
def clear_notification(image, user) do def clear_notification(image, user) do
Notifications.delete_unread_notification("Image", image.id, user) Notifications.delete_unread_notification("Image", image.id, user)
end end

View file

@ -190,6 +190,7 @@ defmodule Philomena.Topics do
|> Repo.delete() |> Repo.delete()
end end
def clear_notification(_topic, nil), do: nil
def clear_notification(topic, user) do def clear_notification(topic, user) do
Notifications.delete_unread_notification("Topic", topic.id, user) Notifications.delete_unread_notification("Topic", topic.id, user)
end end

View file

@ -29,6 +29,9 @@ defmodule PhilomenaWeb.ImageController do
def show(conn, %{"id" => _id}) do def show(conn, %{"id" => _id}) do
image = conn.assigns.image image = conn.assigns.image
user = conn.assigns.current_user
Images.clear_notification(image, user)
comments = comments =
Comment Comment

View file

@ -2,7 +2,7 @@ defmodule PhilomenaWeb.TopicController do
use PhilomenaWeb, :controller use PhilomenaWeb, :controller
alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption} 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.Textile.Renderer
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -22,6 +22,11 @@ defmodule PhilomenaWeb.TopicController do
|> preload([:user, poll: :options]) |> preload([:user, poll: :options])
|> Repo.one() |> Repo.one()
user = conn.assigns.current_user
Topics.clear_notification(topic, user)
Forums.clear_notification(forum, user)
conn = conn |> assign(:topic, topic) conn = conn |> assign(:topic, topic)
%{page_number: page} = conn.assigns.pagination %{page_number: page} = conn.assigns.pagination