simple_notifications 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e098fb2d324d42f603872d4af58a79d3e424f1c1ab262804855c169689b5e6b3
4
- data.tar.gz: 9d57327b0c855b83169836a97d11bb6897980232575dd0918038dc6bfdcc1991
3
+ metadata.gz: b68bdfc2e75a052f2ee8fb130cf00ab4b12ab311c4fd05a64765cb693083b214
4
+ data.tar.gz: 8497e5c83f7a11f8ca096f3c21e04da5eea965d353289dbc3dc2332a5bc0e01d
5
5
  SHA512:
6
- metadata.gz: 228b2186f3465d38a2de8f9cca72677e85e45e78be167f2b86869ffb4060aeb78cf1d984607872db0f982b40d64f2a2f50798fb78b4b4ace9cc0873102a9c9cf
7
- data.tar.gz: 93535ce72ceea4f1932542688a8e29148eee786c6f151282ed01e304eebd80f83ae92ce622fcdc3c584cc43e02e84c7a8acef3e1d4244d1bd3aafbd408fd4560
6
+ metadata.gz: 54a9962147cfacea84a7e8c03ee01472615e3cc178af61920365af53d4f4777d9327b1d16d679e51d63c946f706623599a9b06b6e1ffae2cc2dd40f3bb87195e
7
+ data.tar.gz: 80298c7efe237f9b8e5788b9b9d69aa214daed79a5859f70cd9d4ce0d2aa67f886f2c8a4e6290d887e5888c289129409a912ca3110ae59b4221b0e85a805b9f4
data/README.md CHANGED
@@ -89,7 +89,6 @@ post.notify(sender: :author, receivers: :followers, message: 'My own message')
89
89
  post.notifications
90
90
  post.notifiers
91
91
  post.notificants
92
- post.#{receiver_class}_notificants
93
92
  post.read_marked_notificants
94
93
  post.unread_marked_notificants
95
94
  post.mark_read
@@ -114,7 +113,6 @@ follower.received_notifications
114
113
  ```ruby
115
114
  SimpleNotifications::Record.last.sender
116
115
  SimpleNotifications::Record.last.entity
117
- SimpleNotifications::Record.last.#{receiver_class.name.downcase}_receivers
118
116
  ```
119
117
 
120
118
  ### Skipping Notification
@@ -52,25 +52,8 @@ module SimpleNotifications
52
52
  # Define association for the notified model
53
53
  has_many :notifications, class_name: 'SimpleNotifications::Record', as: :entity
54
54
  has_many :notifiers, through: :notifications, source: :sender, source_type: sender_class(@@options[:sender]).to_s
55
- SimpleNotifications::Record.class_eval do
56
- [@@options[:entity_class].receivers_class(@@options[:receivers])].flatten.each do |receiver_class|
57
- has_many "#{receiver_class.name.downcase}_receivers".to_sym,
58
- through: :deliveries,
59
- source: :receiver,
60
- source_type: receiver_class.name
61
- end
62
- end
63
- [receivers_class(@@options[:receivers])].flatten.each do |receiver_class|
64
- has_many "#{receiver_class.name.downcase}_notificants".to_sym,
65
- through: :notifications,
66
- source: "#{receiver_class.name.downcase}_receivers".to_sym
67
- end
68
55
  has_many :read_deliveries, through: :notifications, source: :read_deliveries
69
56
  has_many :unread_deliveries, through: :notifications, source: :unread_deliveries
70
- # has_many :notificants, through: :notifications, source: :receivers
71
- # has_many :read_notificants, through: :read_deliveries, source: :receiver, source_type: 'User'
72
- # has_many :unread_notificants, through: :unread_deliveries, source: :receiver, source_type: 'User'
73
-
74
57
 
75
58
  # Callbacks
76
59
  after_create_commit :create_notification, if: proc {@@options[:callbacks].include?(:create)}
@@ -125,18 +108,22 @@ module SimpleNotifications
125
108
  end
126
109
 
127
110
  def notificants
128
- #TODO : Need to eager load
129
- SimpleNotifications::Record.where(entity: self).collect {|notification| notification.deliveries.collect(&:receiver)}.flatten
111
+ SimpleNotifications::Record.includes(deliveries: :receiver)
112
+ .collect(&:deliveries).flatten
113
+ .collect(&:receiver)
130
114
  end
131
115
 
132
116
  def read_marked_notificants
133
- #TODO : Need to eager load
134
- SimpleNotifications::Record.where(entity: self).collect {|notification| notification.deliveries.where(is_read: true).collect(&:receiver)}.flatten
117
+ SimpleNotifications::Record.includes(deliveries: :receiver)
118
+ .collect(&:deliveries).flatten
119
+ .select{|record| record.is_read}
120
+ .collect(&:receiver)
135
121
  end
136
122
 
137
123
  def unread_marked_notificants
138
- #TODO : Need to eager load
139
- SimpleNotifications::Record.where(entity: self).collect {|notification| notification.deliveries.where(is_read: false).collect(&:receiver)}.flatten
124
+ SimpleNotifications::Record.includes(deliveries: :receiver)
125
+ .collect(&:deliveries).flatten
126
+ .select{|record| !record.is_read}.collect(&:receiver)
140
127
  end
141
128
 
142
129
  # Mark notifications in read mode.
@@ -1,3 +1,3 @@
1
1
  module SimpleNotifications
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashish Garg