-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ephemeral notifiers #382
Conversation
@viktor-shmigol have you had a chance to test this? |
@excid3 I'm sorry for the long response. I was a little bit busy. class NewMessageNotifier < Noticed::Ephemeral
deliver_by :internal_notification, class: 'DeliveryMethods::InternalNotification'
required_params :message
def channel
"user_#{recipient.id}"
end
def payload
{ body: }
end
def body
I18n.t('notifications.new_message', author: params[:message].author_name)
end
end
class DeliveryMethods::InternalNotification < Noticed::DeliveryMethod
delegate :event, to: :notification
def deliver
ActionCable.server.broadcast(event.channel, event.payload)
end
end
NewMessageNotifier.new(params: {message: Message.last}).deliver(User.last) I'm getting this error: Error performing DeliveryMethods::InternalNotification (Job ID: 0833436a-bbcd-4ee3-811f-ce31362c6d98) from Async(default) in 9.52ms: If I wrap those methods in notification_methods: class NewMessageNotifier < Noticed::Ephemeral
deliver_by :internal_notification, class: 'DeliveryMethods::InternalNotification'
required_params :message
notification_methods do
def channel
"user_#{recipient.id}"
end
def payload
{ body: }
end
def body
I18n.t('notifications.new_message', author: params[:message].author_name)
end
end
end I'm getting this error: NoMethodError: undefined method `notification_methods' for NewMessageNotifier:Class Also, it would be good to have a way to deliver notifications in foreground mode using perform_now. |
@viktor-shmigol Give this a try again. It was retrieving |
I know this is an old PR, but I seem to be missing something: |
@bvogel Please open up a discussion with an example to showcase what you're trying to do. |
thanks: #472 |
This adds an Ephemeral class for sending notifications. This was previously a feature of Noticed v1 but was removed to make solve for bulk notifications. The way things are architected, we can simulate the Notifier & Notification classes for databaseless / ephemeral notifications that should not be saved in the database.
Ephemeral notifiers basically just pass the params and recipients to the delivery method jobs directly. The Notifier and Notification use ActiveModel to set up the same basic attributes as the database models in order to achieve compatibility. It seems to work pretty well.
This is an experimental idea to see if it would be a reasonable solution. There are limitations to this in that config options must be serializable by ActiveJob (meaning Procs and Lambdas cannot be used for delivery method configs, etc).
See #375