activity_notification 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +41 -3
- data/app/jobs/activity_notification/notify_all_job.rb +9 -0
- data/app/jobs/activity_notification/notify_job.rb +9 -0
- data/app/jobs/activity_notification/notify_to_job.rb +9 -0
- data/lib/activity_notification/apis/notification_api.rb +114 -18
- data/lib/activity_notification/config.rb +20 -0
- data/lib/activity_notification/models/concerns/notifiable.rb +63 -0
- data/lib/activity_notification/models/concerns/target.rb +23 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +8 -0
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +6 -0
- data/lib/generators/templates/migrations/migration.rb +5 -5
- data/spec/concerns/apis/notification_api_spec.rb +107 -0
- data/spec/concerns/models/notifiable_spec.rb +25 -4
- data/spec/concerns/models/subscriber_spec.rb +11 -11
- data/spec/concerns/models/target_spec.rb +9 -2
- data/spec/generators/migration/migration_generator_spec.rb +37 -4
- data/spec/jobs/notify_all_job_spec.rb +23 -0
- data/spec/jobs/notify_job_spec.rb +23 -0
- data/spec/jobs/notify_to_job_spec.rb +23 -0
- data/spec/rails_app/app/controllers/comments_controller.rb +4 -1
- data/spec/rails_app/app/models/dummy/dummy_base.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_group.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_notifier.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +1 -0
- data/spec/rails_app/app/models/dummy/dummy_target.rb +1 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +6 -0
- data/spec/rails_app/db/migrate/{20160715050433_create_test_tables.rb → 20160716000000_create_test_tables.rb} +1 -1
- data/spec/rails_app/db/migrate/{20160715050420_create_activity_notification_tables.rb → 20181209000000_create_activity_notification_tables.rb} +3 -3
- data/spec/rails_app/db/schema.rb +43 -43
- data/spec/roles/acts_as_notifiable_spec.rb +45 -0
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6640bcffc0f4acb3afd7021387feb76db52dea7a
|
4
|
+
data.tar.gz: 2ecda41bc9b8e3a76e89a10263cdb805eee2cd63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 961d0f2f0e201522b7e8e2899087dca1f868c0c9950b69d22aa2a69f64a46ddf6d3b0ec3f5f0e5cd22f33afdc27c7670226a3a493ac90848d5496430c6cbfd45
|
7
|
+
data.tar.gz: 2fe01f57e0f14964b77af8d9e9eac995cdb4e8c7a412c8491fe94fe6dd4731a28384dc4c5be4d902591803bcf88b212a88a99002492beda80663f690eeb88eb4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 1.7.0 / 2018-12-09
|
2
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.6.1...v1.7.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Support asynchronous notification API - [#29](https://github.com/simukappu/activity_notification/issues/29)
|
7
|
+
|
8
|
+
Bug Fixes:
|
9
|
+
|
10
|
+
* Fix migration generator to specify the Rails release in generated migration files for Rails 5.x - [#96](https://github.com/simukappu/activity_notification/issues/96)
|
11
|
+
|
12
|
+
Breaking Changes:
|
13
|
+
|
14
|
+
* Change method name of *Target#notify_to* into *Target#receive_notification_of* to avoid ambiguous method name with *Notifiable#notify_to* - [#88](https://github.com/simukappu/activity_notification/issues/88)
|
15
|
+
|
1
16
|
## 1.6.1 / 2018-11-19
|
2
17
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.6.0...v1.6.1)
|
3
18
|
|
data/README.md
CHANGED
@@ -60,6 +60,7 @@
|
|
60
60
|
- [Routes with scope](#routes-with-scope)
|
61
61
|
- [Creating notifications](#creating-notifications)
|
62
62
|
- [Notification API](#notification-api)
|
63
|
+
- [Asynchronous notification API with ActiveJob](#asynchronous-notification-api-with-activejob)
|
63
64
|
- [Automatic tracked notifications](#automatic-tracked-notifications)
|
64
65
|
- [Displaying notifications](#displaying-notifications)
|
65
66
|
- [Preparing target notifications](#preparing-target-notifications)
|
@@ -345,8 +346,7 @@ Then, pages are shown as */myscope/users/1/notifications*.
|
|
345
346
|
|
346
347
|
#### Notification API
|
347
348
|
|
348
|
-
You can trigger notifications by setting all your required parameters and triggering **notify**
|
349
|
-
on the notifiable model, like this:
|
349
|
+
You can trigger notifications by setting all your required parameters and triggering **notify** on the notifiable model, like this:
|
350
350
|
|
351
351
|
```ruby
|
352
352
|
@comment.notify :users, key: "comment.reply"
|
@@ -364,6 +364,31 @@ The new instances of **ActivityNotification::Notification** model will be genera
|
|
364
364
|
*Hint*: *:key* is a option. Default key `#{notifiable_type}.default` which means *comment.default* will be used without specified key.
|
365
365
|
You can override it by *Notifiable#default_notification_key*.
|
366
366
|
|
367
|
+
#### Asynchronous notification API with ActiveJob
|
368
|
+
|
369
|
+
Using Notification API with default configurations, the notifications will be generated synchronously. *activity_notification* also supports **asynchronous notification API** with ActiveJob to improve application performance. You can use **notify_later** method on the notifiable model, like this:
|
370
|
+
|
371
|
+
```ruby
|
372
|
+
@comment.notify_later :users, key: "comment.reply"
|
373
|
+
```
|
374
|
+
|
375
|
+
You can also use *:notify_later* option in *notify* method. This is the same operation as calling *notify_later* method.
|
376
|
+
|
377
|
+
```ruby
|
378
|
+
@comment.notify :users, key: "comment.reply", notify_later: true
|
379
|
+
```
|
380
|
+
|
381
|
+
*Note*: *notify_now* is an alias for *notify* and does the same.
|
382
|
+
|
383
|
+
When you use asynchronous notification API, you should setup ActiveJob with background queuing service such as Sidekiq.
|
384
|
+
You can set *config.active_job_queue* in your initializer to specify a queue name *activity_notification* will use.
|
385
|
+
The default queue name is *:activity_notification*.
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
# Configure ActiveJob queue name for delayed notifications.
|
389
|
+
config.active_job_queue = :my_notification_queue
|
390
|
+
```
|
391
|
+
|
367
392
|
#### Automatic tracked notifications
|
368
393
|
|
369
394
|
You can also generate automatic tracked notifications by **:tracked** option in *acts_as_notifiable*.
|
@@ -404,7 +429,7 @@ class Comment < ActiveRecord::Base
|
|
404
429
|
},
|
405
430
|
# Set { except: [:update] } to :tracked option to generate tracked notifications except update (creation only).
|
406
431
|
# It adds required callbacks to generate notifications for creation of the notifiable model.
|
407
|
-
tracked: { except: [:update], key: 'comment.
|
432
|
+
tracked: { except: [:update], key: 'comment.create.now', send_later: false }
|
408
433
|
end
|
409
434
|
```
|
410
435
|
|
@@ -412,6 +437,19 @@ end
|
|
412
437
|
You can override them by *Notifiable#notification_key_for_tracked_creation* and *Notifiable#notification_key_for_tracked_update*.
|
413
438
|
You can also specify key option in the *:tracked* statement.
|
414
439
|
|
440
|
+
As a default, the notifications will be generated synchronously along with model creation or update. If you want to generate notifications asynchronously, use *:notify_later* option with the *:tracked* option, like this:
|
441
|
+
|
442
|
+
```ruby
|
443
|
+
class Comment < ActiveRecord::Base
|
444
|
+
acts_as_notifiable :users,
|
445
|
+
targets: ->(comment, key) {
|
446
|
+
([comment.article.user] + comment.article.commented_users.to_a - [comment.user]).uniq
|
447
|
+
},
|
448
|
+
# It adds required callbacks to generate notifications asynchronously for creation of the notifiable model.
|
449
|
+
tracked: { only: [:create], key: 'comment.create.later', notify_later: true }
|
450
|
+
end
|
451
|
+
```
|
452
|
+
|
415
453
|
### Displaying notifications
|
416
454
|
|
417
455
|
#### Preparing target notifications
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if defined?(ActiveJob)
|
2
|
+
class ActivityNotification::NotifyAllJob < ActivityNotification.config.parent_job.constantize
|
3
|
+
queue_as ActivityNotification.config.active_job_queue
|
4
|
+
|
5
|
+
def perform(targets, notifiable, options = {})
|
6
|
+
ActivityNotification::Notification.notify_all(targets, notifiable, options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if defined?(ActiveJob)
|
2
|
+
class ActivityNotification::NotifyJob < ActivityNotification.config.parent_job.constantize
|
3
|
+
queue_as ActivityNotification.config.active_job_queue
|
4
|
+
|
5
|
+
def perform(target_type, notifiable, options = {})
|
6
|
+
ActivityNotification::Notification.notify(target_type, notifiable, options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
if defined?(ActiveJob)
|
2
|
+
class ActivityNotification::NotifyToJob < ActivityNotification.config.parent_job.constantize
|
3
|
+
queue_as ActivityNotification.config.active_job_queue
|
4
|
+
|
5
|
+
def perform(target, notifiable, options = {})
|
6
|
+
ActivityNotification::Notification.notify_to(target, notifiable, options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -157,6 +157,7 @@ module ActivityNotification
|
|
157
157
|
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
158
158
|
# @option options [Object] :notifier (nil) Notifier of the notifications
|
159
159
|
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
160
|
+
# @option options [Boolean] :notify_later (false) Whether it generates notifications asynchronously
|
160
161
|
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
161
162
|
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
162
163
|
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
@@ -164,11 +165,48 @@ module ActivityNotification
|
|
164
165
|
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
165
166
|
# @return [Array<Notificaion>] Array of generated notifications
|
166
167
|
def notify(target_type, notifiable, options = {})
|
167
|
-
|
168
|
-
|
169
|
-
|
168
|
+
if options[:notify_later]
|
169
|
+
notify_later(target_type, notifiable, options)
|
170
|
+
else
|
171
|
+
targets = notifiable.notification_targets(target_type, options[:pass_full_options] ? options : options[:key])
|
172
|
+
unless targets.blank?
|
173
|
+
notify_all(targets, notifiable, options)
|
174
|
+
end
|
170
175
|
end
|
171
176
|
end
|
177
|
+
alias_method :notify_now, :notify
|
178
|
+
|
179
|
+
# Generates notifications to configured targets with notifiable model later by ActiveJob queue.
|
180
|
+
#
|
181
|
+
# @example Use with target_type as Symbol
|
182
|
+
# ActivityNotification::Notification.notify_later :users, @comment
|
183
|
+
# @example Use with target_type as String
|
184
|
+
# ActivityNotification::Notification.notify_later 'User', @comment
|
185
|
+
# @example Use with target_type as Class
|
186
|
+
# ActivityNotification::Notification.notify_later User, @comment
|
187
|
+
# @example Use with options
|
188
|
+
# ActivityNotification::Notification.notify_later :users, @comment, key: 'custom.comment', group: @comment.article
|
189
|
+
# ActivityNotification::Notification.notify_later :users, @comment, parameters: { reply_to: @comment.reply_to }, send_later: false
|
190
|
+
#
|
191
|
+
# @param [Symbol, String, Class] target_type Type of target
|
192
|
+
# @param [Object] notifiable Notifiable instance
|
193
|
+
# @param [Hash] options Options for notifications
|
194
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
195
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
196
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
197
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
198
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
199
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
200
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
201
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
202
|
+
# @option options [Boolean] :pass_full_options (false) Whether it passes full options to notifiable.notification_targets, not a key only
|
203
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
204
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
205
|
+
def notify_later(target_type, notifiable, options = {})
|
206
|
+
target_type = target_type.to_s if target_type.is_a? Symbol
|
207
|
+
options.delete(:notify_later)
|
208
|
+
ActivityNotification::NotifyJob.perform_later(target_type, notifiable, options)
|
209
|
+
end
|
172
210
|
|
173
211
|
# Generates notifications to specified targets.
|
174
212
|
#
|
@@ -183,13 +221,42 @@ module ActivityNotification
|
|
183
221
|
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
184
222
|
# @option options [Object] :notifier (nil) Notifier of the notifications
|
185
223
|
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
224
|
+
# @option options [Boolean] :notify_later (false) Whether it generates notifications asynchronously
|
186
225
|
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
187
226
|
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
188
227
|
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
189
228
|
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
190
229
|
# @return [Array<Notificaion>] Array of generated notifications
|
191
230
|
def notify_all(targets, notifiable, options = {})
|
192
|
-
|
231
|
+
if options[:notify_later]
|
232
|
+
notify_all_later(targets, notifiable, options)
|
233
|
+
else
|
234
|
+
targets.map { |target| notify_to(target, notifiable, options) }
|
235
|
+
end
|
236
|
+
end
|
237
|
+
alias_method :notify_all_now, :notify_all
|
238
|
+
|
239
|
+
# Generates notifications to specified targets later by ActiveJob queue.
|
240
|
+
#
|
241
|
+
# @example Notify to all users later
|
242
|
+
# ActivityNotification::Notification.notify_all_later User.all, @comment
|
243
|
+
#
|
244
|
+
# @param [Array<Object>] targets Targets to send notifications
|
245
|
+
# @param [Object] notifiable Notifiable instance
|
246
|
+
# @param [Hash] options Options for notifications
|
247
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
248
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
249
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
250
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
251
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
252
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
253
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
254
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
255
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
256
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
257
|
+
def notify_all_later(targets, notifiable, options = {})
|
258
|
+
options.delete(:notify_later)
|
259
|
+
ActivityNotification::NotifyAllJob.perform_later(targets, notifiable, options)
|
193
260
|
end
|
194
261
|
|
195
262
|
# Generates notifications to one target.
|
@@ -205,27 +272,56 @@ module ActivityNotification
|
|
205
272
|
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
206
273
|
# @option options [Object] :notifier (nil) Notifier of the notifications
|
207
274
|
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
275
|
+
# @option options [Boolean] :notify_later (false) Whether it generates notifications asynchronously
|
208
276
|
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
209
277
|
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
210
278
|
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
211
279
|
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
212
280
|
# @return [Notification] Generated notification instance
|
213
281
|
def notify_to(target, notifiable, options = {})
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
notification
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
282
|
+
if options[:notify_later]
|
283
|
+
notify_later_to(target, notifiable, options)
|
284
|
+
else
|
285
|
+
send_email = options.has_key?(:send_email) ? options[:send_email] : true
|
286
|
+
send_later = options.has_key?(:send_later) ? options[:send_later] : true
|
287
|
+
publish_optional_targets = options.has_key?(:publish_optional_targets) ? options[:publish_optional_targets] : true
|
288
|
+
# Generate notification
|
289
|
+
notification = generate_notification(target, notifiable, options)
|
290
|
+
# Send notification email
|
291
|
+
if notification.present? && send_email
|
292
|
+
notification.send_notification_email({ send_later: send_later })
|
293
|
+
end
|
294
|
+
# Publish to optional targets
|
295
|
+
if notification.present? && publish_optional_targets
|
296
|
+
notification.publish_to_optional_targets(options[:optional_targets] || {})
|
297
|
+
end
|
298
|
+
# Return generated notification
|
299
|
+
notification
|
226
300
|
end
|
227
|
-
|
228
|
-
|
301
|
+
end
|
302
|
+
alias_method :notify_now_to, :notify_to
|
303
|
+
|
304
|
+
# Generates notifications to one target later by ActiveJob queue.
|
305
|
+
#
|
306
|
+
# @example Notify to one user later
|
307
|
+
# ActivityNotification::Notification.notify_later_to @comment.auther, @comment
|
308
|
+
#
|
309
|
+
# @param [Object] target Target to send notifications
|
310
|
+
# @param [Object] notifiable Notifiable instance
|
311
|
+
# @param [Hash] options Options for notifications
|
312
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
313
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
314
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
315
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
316
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
317
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
318
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
319
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
320
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
321
|
+
# @return [Notification] Generated notification instance
|
322
|
+
def notify_later_to(target, notifiable, options = {})
|
323
|
+
options.delete(:notify_later)
|
324
|
+
ActivityNotification::NotifyToJob.perform_later(target, notifiable, options)
|
229
325
|
end
|
230
326
|
|
231
327
|
# Generates a notification
|
@@ -92,6 +92,15 @@ module ActivityNotification
|
|
92
92
|
# @return [String] Base mailer class for email notification.
|
93
93
|
attr_accessor :parent_mailer
|
94
94
|
|
95
|
+
# @overload parent_job
|
96
|
+
# Returns base job class for delayed notifications
|
97
|
+
# @return [String] Base job class for delayed notifications.
|
98
|
+
# @overload parent_job=(value)
|
99
|
+
# Sets base job class for delayed notifications
|
100
|
+
# @param [String] parent_job The new parent_job
|
101
|
+
# @return [String] Base job class for delayed notifications.
|
102
|
+
attr_accessor :parent_job
|
103
|
+
|
95
104
|
# @overload parent_controller
|
96
105
|
# Returns base controller class for notifications_controller
|
97
106
|
# @return [String] Base controller class for notifications_controller.
|
@@ -119,6 +128,15 @@ module ActivityNotification
|
|
119
128
|
# @return [Integer] Default limit to query for opened notifications.
|
120
129
|
attr_accessor :opened_index_limit
|
121
130
|
|
131
|
+
# @overload active_job_queue
|
132
|
+
# Returns ActiveJob queue name for delayed notifications
|
133
|
+
# @return [Symbol] ActiveJob queue name for delayed notifications.
|
134
|
+
# @overload active_job_queue=(value)
|
135
|
+
# Sets ActiveJob queue name for delayed notifications
|
136
|
+
# @param [Symbol] active_job_queue The new active_job_queue
|
137
|
+
# @return [Symbol] ActiveJob queue name for delayed notifications.
|
138
|
+
attr_accessor :active_job_queue
|
139
|
+
|
122
140
|
# @overload :orm
|
123
141
|
# Returns ORM name for ActivityNotification (:active_record or :mongoid)
|
124
142
|
# @return [Boolean] ORM name for ActivityNotification (:active_record or :mongoid).
|
@@ -137,9 +155,11 @@ module ActivityNotification
|
|
137
155
|
@mailer_sender = nil
|
138
156
|
@mailer = 'ActivityNotification::Mailer'
|
139
157
|
@parent_mailer = 'ActionMailer::Base'
|
158
|
+
@parent_job = 'ActiveJob::Base'
|
140
159
|
@parent_controller = 'ApplicationController'
|
141
160
|
@mailer_templates_dir = 'activity_notification/mailer'
|
142
161
|
@opened_index_limit = 10
|
162
|
+
@active_job_queue = :activity_notification
|
143
163
|
@orm = :active_record
|
144
164
|
end
|
145
165
|
|
@@ -249,6 +249,27 @@ module ActivityNotification
|
|
249
249
|
Notification.notify(target_type, self, options)
|
250
250
|
end
|
251
251
|
|
252
|
+
# Generates notifications to configured targets with notifiable model later by ActiveJob queue.
|
253
|
+
# This method calls NotificationApi#notify_later internally with self notifiable instance.
|
254
|
+
# @see NotificationApi#notify_later
|
255
|
+
#
|
256
|
+
# @param [Symbol, String, Class] target_type Type of target
|
257
|
+
# @param [Hash] options Options for notifications
|
258
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
259
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
260
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
261
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
262
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
263
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
264
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
265
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
266
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
267
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
268
|
+
def notify_later(target_type, options = {})
|
269
|
+
Notification.notify_later(target_type, self, options)
|
270
|
+
end
|
271
|
+
alias_method :notify_now, :notify
|
272
|
+
|
252
273
|
# Generates notifications to one target.
|
253
274
|
# This method calls NotificationApi#notify_all internally with self notifiable instance.
|
254
275
|
# @see NotificationApi#notify_all
|
@@ -268,6 +289,27 @@ module ActivityNotification
|
|
268
289
|
def notify_all(targets, options = {})
|
269
290
|
Notification.notify_all(targets, self, options)
|
270
291
|
end
|
292
|
+
alias_method :notify_all_now, :notify_all
|
293
|
+
|
294
|
+
# Generates notifications to one target later by ActiveJob queue.
|
295
|
+
# This method calls NotificationApi#notify_all_later internally with self notifiable instance.
|
296
|
+
# @see NotificationApi#notify_all_later
|
297
|
+
#
|
298
|
+
# @param [Array<Object>] targets Targets to send notifications
|
299
|
+
# @param [Hash] options Options for notifications
|
300
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
301
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
302
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
303
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
304
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
305
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
306
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
307
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
308
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
309
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
310
|
+
def notify_all_later(targets, options = {})
|
311
|
+
Notification.notify_all_later(targets, self, options)
|
312
|
+
end
|
271
313
|
|
272
314
|
# Generates notifications to one target.
|
273
315
|
# This method calls NotificationApi#notify_to internally with self notifiable instance.
|
@@ -288,6 +330,27 @@ module ActivityNotification
|
|
288
330
|
def notify_to(target, options = {})
|
289
331
|
Notification.notify_to(target, self, options)
|
290
332
|
end
|
333
|
+
alias_method :notify_now_to, :notify_to
|
334
|
+
|
335
|
+
# Generates notifications to one target later by ActiveJob queue.
|
336
|
+
# This method calls NotificationApi#notify_later_to internally with self notifiable instance.
|
337
|
+
# @see NotificationApi#notify_later_to
|
338
|
+
#
|
339
|
+
# @param [Object] target Target to send notifications
|
340
|
+
# @param [Hash] options Options for notifications
|
341
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
342
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
343
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
344
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
345
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
346
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
347
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
348
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
349
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
350
|
+
# @return [Notification] Generated notification instance
|
351
|
+
def notify_later_to(target, options = {})
|
352
|
+
Notification.notify_later_to(target, self, options)
|
353
|
+
end
|
291
354
|
|
292
355
|
# Returns default key of the notification.
|
293
356
|
# This method is able to be overriden.
|
@@ -325,10 +325,31 @@ module ActivityNotification
|
|
325
325
|
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
326
326
|
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
327
327
|
# @return [Notification] Generated notification instance
|
328
|
-
def
|
328
|
+
def receive_notification_of(notifiable, options = {})
|
329
329
|
Notification.notify_to(self, notifiable, options)
|
330
330
|
end
|
331
|
-
|
331
|
+
alias_method :receive_notification_now_of, :receive_notification_of
|
332
|
+
|
333
|
+
# Generates notifications to this target later by ActiveJob queue.
|
334
|
+
# This method calls NotificationApi#notify_later_to internally with self target instance.
|
335
|
+
# @see NotificationApi#notify_later_to
|
336
|
+
#
|
337
|
+
# @param [Object] notifiable Notifiable instance to notify
|
338
|
+
# @param [Hash] options Options for notifications
|
339
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
340
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
341
|
+
# @option options [ActiveSupport::Duration] :group_expiry_delay (nil) Expiry period of a notification group
|
342
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
343
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
344
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
345
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
346
|
+
# @option options [Boolean] :publish_optional_targets (true) Whether it publishes notification to optional targets
|
347
|
+
# @option options [Hash<String, Hash>] :optional_targets ({}) Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options
|
348
|
+
# @return [Notification] Generated notification instance
|
349
|
+
def receive_notification_later_of(notifiable, options = {})
|
350
|
+
Notification.notify_later_to(self, notifiable, options)
|
351
|
+
end
|
352
|
+
|
332
353
|
# Opens all notifications of this target.
|
333
354
|
# This method calls NotificationApi#open_all_of internally with self target instance.
|
334
355
|
# @see NotificationApi#open_all_of
|