Skip to content

Commit

Permalink
Merge branch 'main' of github.com:excid3/noticed
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jan 19, 2024
2 parents bc91861 + 5b4e81b commit 0bd255d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NewCommentNotifier < Noticed::Event

deliver_by :email do |config|
config.mailer = "CommentMailer"
config.if = ->(recipient) { !!recipient.preferences[:email] }
config.if = ->(recipient) { !!recipient.preferences[:email] }
end

bulk_deliver_by :discord do |config|
Expand Down Expand Up @@ -201,7 +201,7 @@ en:
notifiers:
new_comment_notifier:
notification:
message: "Someone posted a new comment!"
message: "Someone posted a new comment!"
```
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).
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end

# Migrate each record to the new tables
Notification.find_each do |notification|
attributes = notification.attributes.slice("id", "type").with_indifferent_access
attributes = notification.attributes.slice("type").with_indifferent_access
attributes[:type] = attributes[:type].sub("Notification", "Notifier")
attributes[:params] = Noticed::Coder.load(notification.params)
attributes[:params] = {} if attributes[:params].try(:has_key?, "noticed_error") # Skip invalid records
Expand Down
30 changes: 4 additions & 26 deletions docs/delivery_methods/action_cable.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Sends a notification to the browser via websockets (ActionCable channel by defau

```ruby
deliver_by :action_cable do |config|
config.channel = "NotificationsChannel"
config.channel = "Noticed::NotificationsChannel"
config.stream = ->{ recipient }
config.message = ->{ params.merge( user_id: recipient.id) }
end
Expand All @@ -18,37 +18,15 @@ end

* `channel`

Override the ActionCable channel used to send notifications.
Override the ActionCable channel used to send notifications. Defaults to `Noticed::NotificationChannel`

* `stream`

The stream that is broadcasted to.
Should return the stream the message is broadcasted to. Defaults to `recipient`

## Authentication

To send notifications to individual users, you'll want to use `stream_for current_user`

```ruby
class NotificationChannel < ApplicationCable::Channel
def subscribed
stream_for current_user
end

def unsubscribed
stop_all_streams
end

def mark_as_seen(data)
current_user.notifications.where(id: data["ids"]).mark_as_seen
end

def mark_as_read(data)
current_user.notifications.where(id: data["ids"]).mark_as_read
end
end
```

This requires `identified_by :current_user` in your ApplicationCable::Connection. For example, using Devise for authentication:
To send notifications to individual users, you'll want to use `stream_for current_user`. This requires `identified_by :current_user` in your ApplicationCable::Connection. For example, using Devise for authentication:

```ruby
module ApplicationCable
Expand Down

0 comments on commit 0bd255d

Please sign in to comment.