Commit 95945274 by tady

通知を1周間より最近なものに限定

parent ed89824d
...@@ -19,11 +19,14 @@ class Notification < ActiveRecord::Base ...@@ -19,11 +19,14 @@ class Notification < ActiveRecord::Base
# Named scope # Named scope
###################################################################### ######################################################################
# 最新のPostを取得
scope :unread, -> { scope :unread, -> {
where(is_read: false) where(is_read: false)
} }
scope :recent, -> {
where(arel_table[:created_at].gt 7.day.ago)
}
###################################################################### ######################################################################
# Instance method # Instance method
###################################################################### ######################################################################
......
...@@ -115,7 +115,9 @@ class User < ActiveRecord::Base ...@@ -115,7 +115,9 @@ class User < ActiveRecord::Base
# push通知を追加 # push通知を追加
def push_notification(detail_path, body) def push_notification(detail_path, body)
notifications.create(detail_path: detail_path, body: body, is_read: false) unless notifications.where(detail_path: detail_path).unread.exists?
notifications.create(detail_path: detail_path, body: body, is_read: false)
end
end end
# record footprint # record footprint
......
...@@ -30,7 +30,7 @@ nav.navbar.navbar-fixed-top.navbar-original role="navigation" ...@@ -30,7 +30,7 @@ nav.navbar.navbar-fixed-top.navbar-original role="navigation"
a#notifications data-container="body" data-toggle="popover" data-placement="bottom" a#notifications data-container="body" data-toggle="popover" data-placement="bottom"
span.glyphicon.glyphicon-flag span.glyphicon.glyphicon-flag
- if current_user.notifications.unread.any? - if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count span.badge = current_user.notifications.unread.recent.count
li.new-post-btn li.new-post-btn
form form
a.btn.navbar-btn href=new_post_path a.btn.navbar-btn href=new_post_path
...@@ -56,10 +56,10 @@ nav.navbar.navbar-fixed-top.navbar-original role="navigation" ...@@ -56,10 +56,10 @@ nav.navbar.navbar-fixed-top.navbar-original role="navigation"
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
script#notification-content type="text/template" script#notification-content type="text/template"
- if current_user.notifications.unread.any? - if current_user.notifications.unread.recent.any?
h4 通知一覧 h4 通知一覧
.list-group .list-group
- current_user.notifications.unread.each do |notification| - current_user.notifications.unread.recent.each do |notification|
a.list-group-item href=notification_bridge_path(notification.id) a.list-group-item href=notification_bridge_path(notification.id)
spen.small spen.small
| [#{notification.created_at.strftime('%m/%d %H:%M')}]&nbsp; | [#{notification.created_at.strftime('%m/%d %H:%M')}]&nbsp;
......
...@@ -32,6 +32,16 @@ describe Notification do ...@@ -32,6 +32,16 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not duplicated notifies on post edited" do
@bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy
@post.reload
expect(@post.watchers).to include(@bob)
@post.update!(title: @post.title + ' [New!]')
@post.update!(title: @post.title + ' [New!]')
expect(@bob.notifications.size).to eq(1)
end
it "not notifies on post edited by him" do it "not notifies on post edited by him" do
@bob.watch!(post: @post) @bob.watch!(post: @post)
@post.reload @post.reload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment