Replies: 2 comments 8 replies
-
You should just choose the correct class, not duplicate the code if all the params are the same: users.find_each do |user|
next unless database_deliver?(user) || push_deliver?(user)
notifier = database_deliver? ? SomeEventNotifier : SomeEphemeralEventNotifier
notifier.with(
attribute: @event_log.target_record.foo,
subject: @event_log.target_record,
version: 1
).deliver(user) And you can use a Concern to share the delivery methods between the two types of notifiers. class SomeEventNotifier < Noticed::Event
include SomeEvent::DeliveryMethods
end class SomeEventEphemeralNotifier < Noticed::Event
include SomeEvent::DeliveryMethods
end module SomeEvent::DeliveryMethods
extend ActiveSupport::Concern
included do
deliver_by :fcm do |config|
config.credentials = :firebase_credentials
config.device_tokens = :fcm_device_tokens
config.json = :firebase_notification
config.if = :push_deliver?
end
end
end I haven't seen a good argument for why you'd want to sometimes deliver a notification to the database and sometimes not. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Hi everyone! We have the same issue on our project. We want to be able to save notifications into DB conditionally. @bvogel How did you deal with conditional saving to DB after migration to V2? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
WRT to #382
I know that is an old PR, but I seem to be missing something:
we have user options that allow our users to determine which kind of notifications they will receive. With v1 there was a setting for web/database and a setting for push/fcm. So the combinations are both (web/push), only web (web/-), only push (-/push) and none at all (-/-) With the v2 options I can cover easily "both", "only web" and "none" - however for "only push" I'd need an ephemeral notifier - does that mean I need to double the code for all notifiers (currently 14 different ones) and select either the regular or the ephemeral based on the users setting? Is that how this is supposed to work? TBH the previous if: for the database method was much more serviceable.
so before (v1) we had
with
database_deliver?
andpush_deliver?
checking each users settings for each notification type.Now I have
caller was something like this:
now I'd need to do:
with
SomeEphemeralEventNotifier
being a 1:1 copy of the original one just with a different base class?Beta Was this translation helpful? Give feedback.
All reactions