forked from khun84/rpush
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CHANGELOG.md Implement proof of concept authorization Fix logger error Add some fields to AndroidNotification Remove notification node from message payload for FCM notifications There is a type mismatch between message.notification and message.android.notification. The message.notification only accepts the attributes title, body, and image, whereas message.android.notification holds all the rest of the configuration. So in order to use message.notification along with message.android.notification there would be the need for an additional database field called something like android_configuration Fix notification handling in fcm/notification.rb See https://github.com/rpush/rpush/pull/620\#discussion_r710926868 for further information Add comment to necessary_data_exists? method Stop auto-closing issues Not the same, but similar rationale to what Rails did recently: rails/rails@acf4816 Bump rack from 2.2.3 to 2.2.3.1 (rpush#638) Bump rails-html-sanitizer from 1.4.2 to 1.4.3 (rpush#642) Fix - missing gcm interface fix code formatting - no change Payload Data Size is now calculated based off the message data attribute Priority value is now using 'normal' or 'high' instead of numeric values Dry Run option is not implemented so throws an exception Mutable Content is not implemented so throws an exception Adding tests Removing debug line Adding debug line requested in PR rpush#620 Get tests working without all the ENV variables Add properties to FCM App to allow operation without env vars Adding new attributes to redis model Adding 7.1 migration to active record tests. Updating Gemfile.lock FCM returning error when data is sent in Android payload Moving notification keys to the correct location - only supporting Android As the FCM code moves around notification keys, it would be good to handle both stirng and symbol keys. - Calling hook fcm_invalid_device_token if we get an invalid token response from FCM - Adding specs for FCM daemon - Clarifying error message Adding a google credential cache Fixing Logging Adding a google credential cache Remove content_available from FCM implementation. It doesn't appear to be suported in Android
- Loading branch information
Showing
41 changed files
with
946 additions
and
52 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Rpush710Updates < ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] | ||
def self.up | ||
add_column :rpush_apps, :firebase_project_id, :string | ||
add_column :rpush_apps, :json_key, :text | ||
end | ||
|
||
def self.down | ||
remove_column :rpush_apps, :firebase_project_id | ||
remove_column :rpush_apps, :json_key | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
require 'active_support/all' | ||
require 'net-http2' | ||
require 'jwt' | ||
require 'googleauth' | ||
|
||
require 'rails' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Rpush | ||
module Client | ||
module ActiveModel | ||
module Fcm | ||
module App | ||
def self.included(base) | ||
base.instance_eval do | ||
# TODO: Add whatever validation is needed here | ||
# validates :auth_key, presence: true | ||
end | ||
end | ||
|
||
def service_name | ||
'fcm' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
lib/rpush/client/active_model/fcm/expiry_collapse_key_mutual_inclusion_validator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Rpush | ||
module Client | ||
module ActiveModel | ||
module Fcm | ||
class ExpiryCollapseKeyMutualInclusionValidator < ::ActiveModel::Validator | ||
def validate(record) | ||
return unless record.collapse_key && !record.expiry | ||
record.errors.add :expiry, 'must be set when using a collapse_key' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
module Rpush | ||
module Client | ||
module ActiveModel | ||
module Fcm | ||
module Notification | ||
FCM_PRIORITY_HIGH = Rpush::Client::ActiveModel::Apns::Notification::APNS_PRIORITY_IMMEDIATE | ||
FCM_PRIORITY_NORMAL = Rpush::Client::ActiveModel::Apns::Notification::APNS_PRIORITY_CONSERVE_POWER | ||
FCM_PRIORITIES = [FCM_PRIORITY_HIGH, FCM_PRIORITY_NORMAL] | ||
|
||
ROOT_NOTIFICATION_KEYS = %w[title body image].freeze | ||
ANDROID_NOTIFICATION_KEYS = %w[icon tag color click_action body_loc_key body_loc_args title_loc_key | ||
title_loc_args channel_id ticker sticky event_time local_only | ||
default_vibrate_timings default_light_settings vibrate_timings | ||
visibility notification_count light_settings].freeze | ||
|
||
def self.included(base) | ||
base.instance_eval do | ||
validates :device_token, presence: true | ||
validates :priority, inclusion: { in: FCM_PRIORITIES }, allow_nil: true | ||
|
||
validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096 | ||
validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000 | ||
|
||
validates_with Rpush::Client::ActiveModel::Fcm::ExpiryCollapseKeyMutualInclusionValidator | ||
validates_with Rpush::Client::ActiveModel::Fcm::NotificationKeysInAllowedListValidator | ||
end | ||
end | ||
|
||
def payload_data_size | ||
multi_json_dump(as_json['message']['data']).bytesize | ||
end | ||
|
||
# This is a hack. The schema defines `priority` to be an integer, but FCM expects a string. | ||
# But for users of rpush to have an API they might expect (setting priority to `high`, not 10) | ||
# we do a little conversion here. | ||
def priority=(priority) | ||
case priority | ||
when 'high', FCM_PRIORITY_HIGH | ||
super(FCM_PRIORITY_HIGH) | ||
when 'normal', FCM_PRIORITY_NORMAL | ||
super(FCM_PRIORITY_NORMAL) | ||
else | ||
errors.add(:priority, 'must be one of either "normal" or "high"') | ||
end | ||
end | ||
|
||
def dry_run=(value) | ||
fail ArgumentError, 'FCM does not support dry run' if value | ||
end | ||
|
||
def mutable_content=(value) | ||
fail ArgumentError, 'RPush does not currently support mutable_content for FCM' if value | ||
end | ||
|
||
def as_json(options = nil) # rubocop:disable Metrics/PerceivedComplexity | ||
json = { | ||
'data' => data, | ||
'android' => android_config, | ||
'token' => device_token | ||
} | ||
# Android does not appear to handle content_available anymore. Instead "priority" should be used | ||
# with "low" being a background only message. APN however should support this field. | ||
# json['content_available'] = content_available if content_available | ||
json['notification'] = root_notification if notification | ||
{ 'message' => json } | ||
end | ||
|
||
def android_config | ||
json = { | ||
'notification' => android_notification, | ||
} | ||
json['collapse_key'] = collapse_key if collapse_key | ||
json['priority'] = priority_str if priority | ||
json['ttl'] = "#{expiry}s" if expiry | ||
json | ||
end | ||
|
||
def notification=(value) | ||
super(value.with_indifferent_access) | ||
end | ||
|
||
def root_notification | ||
return {} unless notification | ||
|
||
notification.slice(*ROOT_NOTIFICATION_KEYS) | ||
end | ||
|
||
def android_notification | ||
json = notification&.slice(*ANDROID_NOTIFICATION_KEYS) || {} | ||
json['notification_priority'] = priority_for_notification if priority | ||
json['sound'] = sound if sound | ||
json['default_sound'] = !sound || sound == 'default' ? true : false | ||
json | ||
end | ||
|
||
def priority_str | ||
case | ||
when priority <= 5 then 'normal' | ||
else | ||
'high' | ||
end | ||
end | ||
|
||
def priority_for_notification | ||
case priority | ||
when 0 then 'PRIORITY_UNSPECIFIED' | ||
when 1 then 'PRIORITY_MIN' | ||
when 2 then 'PRIORITY_LOW' | ||
when 5 then 'PRIORITY_DEFAULT' | ||
when 6 then 'PRIORITY_HIGH' | ||
when 10 then 'PRIORITY_MAX' | ||
else | ||
'PRIORITY_DEFAULT' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.