noticed 2.0.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75c02b0c74747522809dcb6d841016c48b91d8b5c6f637efb3fbd68729babb59
4
- data.tar.gz: 01f8b8a9c4f185c48729a7c073915194c4e872f8f412ed1a3c94b763f7134ec9
3
+ metadata.gz: cf12a81661e3c6fa7e6240e54f6cb802420b13e2cfd35feabdc713a415986b5a
4
+ data.tar.gz: '08074571747ce14478e7f45de5917700fa997caefd0bb93b3bd154287f3b7830'
5
5
  SHA512:
6
- metadata.gz: 2a5e8023362194fbdb682faa7f608101e54c67df6916e7a5faac7252852196618518d405f233720d7fb843b6a67e4757a29da189b9dd7c084cca135b3caf1226
7
- data.tar.gz: e475367cb48916b2fa796076b057c3eb215a9046cf286f958b11b8c99f294feec5b646b21ce5def9c0208c3293a34cbc434ecc831d4f7e1b7fc51659fc9f3512
6
+ metadata.gz: c5ed4a60a134a094a9837127d2ac5aaab7ab2bae500222861ebb99e3053ef8450a439093543f03f58fefe5d1df04b47e519bfcfb3193b2aa82262bb5d725fe7a
7
+ data.tar.gz: 4cfcb122083862b7400459b99695619fabafb8676ea44e5185a06f85eaa693cc12a4eca0fb3094a0c502017fe0b67767d5853ec72e5928b4b560209189e95c4e
data/README.md CHANGED
@@ -87,7 +87,7 @@ class NewCommentNotifier < Noticed::Event
87
87
 
88
88
  deliver_by :email do |config|
89
89
  config.mailer = "CommentMailer"
90
- config.if = ->(recipient) { !!recipient.preferences[:email] }
90
+ config.if = ->(recipient) { !!recipient.preferences[:email] }
91
91
  end
92
92
 
93
93
  bulk_deliver_by :discord do |config|
@@ -201,7 +201,7 @@ en:
201
201
  notifiers:
202
202
  new_comment_notifier:
203
203
  notification:
204
- message: "Someone posted a new comment!"
204
+ message: "Someone posted a new comment!"
205
205
  ```
206
206
 
207
207
  Or, if you have your Notifier within another module, such as `Admin::NewCommentNotifier`, the resulting lookup path will be `en.notifiers.admin.new_comment_notifier.notification.message` (modules become nesting steps).
@@ -0,0 +1,19 @@
1
+ module Noticed
2
+ class NotificationChannel < ApplicationCable::Channel
3
+ def subscribed
4
+ stream_for current_user
5
+ end
6
+
7
+ def unsubscribed
8
+ stop_all_streams
9
+ end
10
+
11
+ def mark_as_seen(data)
12
+ current_user.notifications.where(id: data["ids"]).mark_as_seen
13
+ end
14
+
15
+ def mark_as_read(data)
16
+ current_user.notifications.where(id: data["ids"]).mark_as_read
17
+ end
18
+ end
19
+ end
@@ -7,12 +7,20 @@ module Noticed
7
7
  class NotifierGenerator < Rails::Generators::NamedBase
8
8
  include Rails::Generators::ResourceHelpers
9
9
 
10
+ check_class_collision suffix: "Notifier"
11
+
10
12
  source_root File.expand_path("../templates", __FILE__)
11
13
 
12
14
  desc "Generates a notification with the given NAME."
13
15
 
14
16
  def generate_notification
15
- template "notifier.rb", "app/notifiers/#{file_path}.rb"
17
+ template "notifier.rb", "app/notifiers/#{file_path}_notifier.rb"
18
+ end
19
+
20
+ private
21
+
22
+ def file_name # :doc:
23
+ @_file_name ||= super.sub(/_notifier\z/i, "")
16
24
  end
17
25
  end
18
26
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # <%= class_name %>.with(record: @post, message: "New post").deliver(User.all)
4
4
 
5
- class <%= class_name %> < Noticed::Event
5
+ class <%= class_name %>Notifier < Noticed::Event
6
6
  # Add your delivery methods
7
7
  #
8
8
  # deliver_by :email do |config|
@@ -40,7 +40,7 @@ module Noticed
40
40
 
41
41
  # Call method if symbol and matching method on Notifier
42
42
  elsif option.is_a?(Symbol) && event.respond_to?(option)
43
- event.send(option, self)
43
+ event.send(option, notification)
44
44
 
45
45
  # Return the value
46
46
  else
@@ -1,11 +1,11 @@
1
1
  module Noticed
2
2
  module DeliveryMethods
3
3
  class ActionCable < DeliveryMethod
4
- required_options :channel, :stream, :message
4
+ required_options :message
5
5
 
6
6
  def deliver
7
- channel = fetch_constant(:channel)
8
- stream = evaluate_option(:stream)
7
+ channel = fetch_constant(:channel) || Noticed::NotificationChannel
8
+ stream = evaluate_option(:stream) || recipient
9
9
  message = evaluate_option(:message)
10
10
 
11
11
  channel.broadcast_to stream, message
@@ -1,3 +1,3 @@
1
1
  module Noticed
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noticed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -35,6 +35,7 @@ files:
35
35
  - MIT-LICENSE
36
36
  - README.md
37
37
  - Rakefile
38
+ - app/channels/noticed/notification_channel.rb
38
39
  - app/jobs/noticed/application_job.rb
39
40
  - app/jobs/noticed/event_job.rb
40
41
  - app/models/concerns/noticed/deliverable.rb