Skip to content

Commit

Permalink
Notificaiton.read! now required user argument.
Browse files Browse the repository at this point in the history
```rb
Notificaiton.read!(current_user, params[:ids])
```

Add `POST /notifications/read` API for markup ids as read.
  • Loading branch information
huacnlee committed Oct 9, 2020
1 parent 1cb0996 commit 3162b19
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 173 deletions.
3 changes: 2 additions & 1 deletion Gemfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ gem 'uglifier'
gem 'coffee-rails'
gem 'devise'
gem 'jquery-rails'
gem 'mysql2'
gem 'pg'
gem 'puma'
gem 'bootstrap'
gem 'sprockets'

group :development, :test do
gem 'minitest'
Expand Down
204 changes: 95 additions & 109 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,97 +1,96 @@
PATH
remote: .
specs:
notifications (1.0.0)
notifications (1.1.0)
kaminari (>= 0.15)
rails (>= 5.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.3)
actionpack (= 5.2.3)
actioncable (5.2.4.4)
actionpack (= 5.2.4.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
actionmailer (5.2.4.4)
actionpack (= 5.2.4.4)
actionview (= 5.2.4.4)
activejob (= 5.2.4.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
rack (~> 2.0)
actionpack (5.2.4.4)
actionview (= 5.2.4.4)
activesupport (= 5.2.4.4)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.3)
activesupport (= 5.2.3)
actionview (5.2.4.4)
activesupport (= 5.2.4.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.3)
activesupport (= 5.2.3)
activejob (5.2.4.4)
activesupport (= 5.2.4.4)
globalid (>= 0.3.6)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
activemodel (5.2.4.4)
activesupport (= 5.2.4.4)
activerecord (5.2.4.4)
activemodel (= 5.2.4.4)
activesupport (= 5.2.4.4)
arel (>= 9.0)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
activestorage (5.2.4.4)
actionpack (= 5.2.4.4)
activerecord (= 5.2.4.4)
marcel (~> 0.3.1)
activesupport (5.2.3)
activesupport (5.2.4.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
autoprefixer-rails (9.5.0)
autoprefixer-rails (10.0.1.0)
execjs
bcrypt (3.1.12)
bootstrap (4.3.1)
bcrypt (3.1.16)
bootstrap (4.5.2)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
builder (3.2.3)
codecov (0.1.14)
builder (3.2.4)
codecov (0.2.11)
json
simplecov
url
coffee-rails (4.2.2)
coffee-rails (5.0.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
railties (>= 5.2.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
devise (4.6.2)
concurrent-ruby (1.1.7)
crass (1.0.6)
devise (4.7.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
docile (1.3.1)
erubi (1.8.0)
docile (1.3.2)
erubi (1.9.0)
execjs (2.7.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
ffi (1.10.0)
factory_bot (6.1.0)
activesupport (>= 5.0.0)
ffi (1.13.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jquery-rails (4.3.3)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.2.0)
json (2.3.1)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
Expand All @@ -104,104 +103,90 @@ GEM
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
loofah (2.2.3)
loofah (2.7.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
mysql2 (0.5.2)
nio4r (2.3.1)
nokogiri (1.10.2)
minitest (5.14.2)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
popper_js (1.14.5)
puma (3.12.1)
rack (2.0.6)
pg (1.2.3)
popper_js (1.16.0)
puma (5.0.2)
nio4r (~> 2.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.3)
actioncable (= 5.2.3)
actionmailer (= 5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
activemodel (= 5.2.3)
activerecord (= 5.2.3)
activestorage (= 5.2.3)
activesupport (= 5.2.3)
rails (5.2.4.4)
actioncable (= 5.2.4.4)
actionmailer (= 5.2.4.4)
actionpack (= 5.2.4.4)
actionview (= 5.2.4.4)
activejob (= 5.2.4.4)
activemodel (= 5.2.4.4)
activerecord (= 5.2.4.4)
activestorage (= 5.2.4.4)
activesupport (= 5.2.4.4)
bundler (>= 1.3.0)
railties (= 5.2.3)
railties (= 5.2.4.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.3)
actionpack (= 5.2.3)
activesupport (= 5.2.3)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (5.2.4.4)
actionpack (= 5.2.4.4)
activesupport (= 5.2.4.4)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
sass (3.7.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.0.1)
rake (13.0.1)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
rake
sassc-rails (2.1.0)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
simplecov (0.16.1)
simplecov (0.19.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sprockets (3.7.2)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.3)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.9)
tzinfo (1.2.5)
tilt (2.0.10)
tzinfo (1.2.7)
thread_safe (~> 0.1)
uglifier (4.1.20)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
url (0.3.2)
warden (1.2.8)
rack (>= 2.0.6)
websocket-driver (0.7.0)
warden (1.2.9)
rack (>= 2.0.9)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
websocket-extensions (0.1.5)

PLATFORMS
ruby
Expand All @@ -214,13 +199,14 @@ DEPENDENCIES
factory_bot
jquery-rails
minitest
mysql2
notifications!
pg
puma
rails (~> 5.2.0)
sass-rails
simplecov
sprockets
uglifier

BUNDLED WITH
1.17.2
2.1.4
6 changes: 5 additions & 1 deletion app/controllers/notifications/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ def index
@notifications = notifications.includes(:actor).order("id desc").page(params[:page])

unread_ids = @notifications.reject(&:read?).select(&:id)
Notification.read!(unread_ids)
Notification.read!(current_user, unread_ids)

@notification_groups = @notifications.group_by { |note| note.created_at.to_date }
end

def read
Notification.read!(current_user, params[:ids])
end

def clean
notifications.delete_all
redirect_to notifications_path
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resources :notifications, path: "" do
collection do
delete :clean
post :read
end
end
end
12 changes: 12 additions & 0 deletions lib/notifications/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Notifications
class Base
extend ActiveSupport::Concern

included do
end

class_methods do
def
end
end
end
4 changes: 2 additions & 2 deletions lib/notifications/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def actor_profile_url
end

module ClassMethods
def read!(ids = [])
def read!(user, ids = [])
return if ids.blank?
Notification.where(id: ids).update_all(read_at: Time.now)
Notification.where(user: user, id: ids).update_all(read_at: Time.now)
end

def unread_count(user)
Expand Down
2 changes: 1 addition & 1 deletion lib/notifications/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Notifications
VERSION = "1.0.0"
VERSION = "1.1.0"
end
1 change: 0 additions & 1 deletion test/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link action_draft_manifest.js
Loading

0 comments on commit 3162b19

Please sign in to comment.