Retrospring/app/models/user/push_notification_methods.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
677 B
Ruby
Raw Normal View History

2022-09-11 14:20:10 -07:00
# frozen_string_literal: true
module User::PushNotificationMethods
def push_notification(app, resource)
raise ArgumentError("Resource must respond to `as_push_notification`") unless resource.respond_to? :as_push_notification
web_push_subscriptions.active.find_each do |s|
n = Rpush::Webpush::Notification.new
n.app = app
n.registration_ids = [s.subscription.symbolize_keys]
n.data = {
2023-02-25 06:46:34 -08:00
message: resource.as_push_notification.merge(notification_data).to_json,
}
n.save!
PushNotificationWorker.perform_async(n.id)
end
end
2023-02-25 06:46:34 -08:00
def notification_data = {
data: {
badge: unread_inbox_count,
2023-02-25 06:46:34 -08:00
},
}
end