-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
12 changed files
with
276 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.notification-type-block:not(:last-child) { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.notification { | ||
margin-bottom: 0; | ||
} | ||
|
||
.notification:not(:last-child) { | ||
border-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
defmodule Philomena.Notifications.Category do | ||
@moduledoc """ | ||
Notification category determination. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Philomena.Notifications.Notification | ||
|
||
@type t :: | ||
:channel_live | ||
| :forum_post | ||
| :forum_topic | ||
| :gallery_image | ||
| :image_comment | ||
| :image_merge | ||
|
||
@doc """ | ||
Return a list of all supported types. | ||
""" | ||
def types do | ||
[ | ||
:channel_live, | ||
:forum_topic, | ||
:gallery_image, | ||
:image_comment, | ||
:image_merge, | ||
:forum_post | ||
] | ||
end | ||
|
||
@doc """ | ||
Determine the type of a `m:Philomena.Notifications.Notification`. | ||
""" | ||
def notification_type(n) do | ||
case {n.actor_type, n.actor_child_type} do | ||
{"Channel", _} -> | ||
:channel_live | ||
|
||
{"Gallery", _} -> | ||
:gallery_image | ||
|
||
{"Image", "Comment"} -> | ||
:image_comment | ||
|
||
{"Image", _} -> | ||
:image_merge | ||
|
||
{"Topic", "Post"} -> | ||
if n.action == "posted a new reply in" do | ||
:forum_post | ||
else | ||
:forum_topic | ||
end | ||
end | ||
end | ||
|
||
@doc """ | ||
Returns an `m:Ecto.Query` that finds notifications for the given type. | ||
""" | ||
def query_for_type(type) do | ||
base = from(n in Notification) | ||
|
||
case type do | ||
:channel_live -> | ||
where(base, [n], n.actor_type == "Channel") | ||
|
||
:gallery_image -> | ||
where(base, [n], n.actor_type == "Gallery") | ||
|
||
:image_comment -> | ||
where(base, [n], n.actor_type == "Image" and n.actor_child_type == "Comment") | ||
|
||
:image_merge -> | ||
where(base, [n], n.actor_type == "Image" and is_nil(n.actor_child_type)) | ||
|
||
:forum_topic -> | ||
where( | ||
base, | ||
[n], | ||
n.actor_type == "Topic" and n.actor_child_type == "Post" and | ||
n.action != "posted a new reply in" | ||
) | ||
|
||
:forum_post -> | ||
where( | ||
base, | ||
[n], | ||
n.actor_type == "Topic" and n.actor_child_type == "Post" and | ||
n.action == "posted a new reply in" | ||
) | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
lib/philomena_web/controllers/notification/category_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule PhilomenaWeb.Notification.CategoryController do | ||
use PhilomenaWeb, :controller | ||
|
||
alias Philomena.Notifications | ||
|
||
def show(conn, params) do | ||
type = category(params) | ||
|
||
notifications = | ||
Notifications.unread_notifications_for_user_and_type( | ||
conn.assigns.current_user, | ||
type, | ||
conn.assigns.scrivener | ||
) | ||
|
||
render(conn, "show.html", | ||
title: "Notification Area", | ||
notifications: notifications, | ||
type: type | ||
) | ||
end | ||
|
||
defp category(params) do | ||
case params["id"] do | ||
"channel_live" -> :channel_live | ||
"gallery_image" -> :gallery_image | ||
"image_comment" -> :image_comment | ||
"image_merge" -> :image_merge | ||
"forum_topic" -> :forum_topic | ||
_ -> :forum_post | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/philomena_web/templates/notification/_notification.html.slime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
lib/philomena_web/templates/notification/category/show.html.slime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
h1 Notification Area | ||
.walloftext | ||
= cond do | ||
- Enum.any?(@notifications) -> | ||
- route = fn p -> ~p"/notifications/categories/#{@type}?#{p}" end | ||
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @notifications, route: route, conn: @conn | ||
|
||
.block.notification-type-block | ||
.block__header | ||
span.block__header__title = name_of_type(@type) | ||
.block__header.block__header__sub | ||
= pagination | ||
|
||
div | ||
= for notification <- @notifications do | ||
= render PhilomenaWeb.NotificationView, "_notification.html", notification: notification, conn: @conn | ||
|
||
.block__header.block__header--light | ||
= pagination | ||
|
||
- true -> | ||
p You currently have no notifications of this category. | ||
p | ||
' To get notifications on new comments and forum posts, click the | ||
' 'Subscribe' button in the bar at the top of an image or forum topic. | ||
|
||
a.button href=~p"/notifications" | ||
' View all notifications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule PhilomenaWeb.Notification.CategoryView do | ||
use PhilomenaWeb, :view | ||
|
||
defdelegate name_of_type(type), to: PhilomenaWeb.NotificationView | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters