Skip to content

Commit

Permalink
Bump version to v7.0.1
Browse files Browse the repository at this point in the history
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
aried3r authored and pechorin committed Jun 19, 2024
1 parent b259a66 commit 2706127
Show file tree
Hide file tree
Showing 41 changed files with 946 additions and 52 deletions.
25 changes: 0 additions & 25 deletions .github/stale.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [v7.0.1](https://github.com/rpush/rpush/tree/v7.0.1) (2022-03-02)

[Full Changelog](https://github.com/rpush/rpush/compare/v7.0.0...v7.0.1)

**Merged pull requests:**

- Fix deprecation warnings from the redis gem [\#636](https://github.com/rpush/rpush/pull/636) ([sharang-d](https://github.com/sharang-d))

## [Unreleased](https://github.com/rpush/rpush/tree/HEAD)

[Full Changelog](https://github.com/rpush/rpush/compare/v7.0.0...HEAD)
Expand Down
66 changes: 47 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
rpush (7.0.0)
rpush (7.1.0)
activesupport (>= 5.2)
googleauth
jwt (>= 1.5.6)
multi_json (~> 1.0)
net-http-persistent
Expand Down Expand Up @@ -38,6 +39,8 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
appraisal (2.4.1)
bundler
rake
Expand All @@ -58,17 +61,30 @@ GEM
database_cleaner-core (2.0.1)
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.10.0)
erubi (1.12.0)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
net-http
google-cloud-env (2.1.0)
faraday (>= 1.0, < 3.a)
googleauth (1.9.2)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hkdf (0.3.0)
http-2 (0.11.0)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
jwt (2.3.0)
loofah (2.14.0)
jwt (2.7.1)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
nokogiri (>= 1.12.0)
method_source (1.0.0)
mini_portile2 (2.8.0)
mini_portile2 (2.8.5)
minitest (5.15.0)
modis (4.0.1)
activemodel (>= 5.2)
Expand All @@ -79,26 +95,32 @@ GEM
msgpack (1.4.5)
multi_json (1.15.0)
mysql2 (0.5.3)
net-http-persistent (4.0.1)
net-http (0.4.1)
uri
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-http2 (0.18.4)
net-http2 (0.18.5)
http-2 (~> 0.11)
nokogiri (1.13.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.16.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
os (1.1.4)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
pg (1.2.3)
racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
public_suffix (5.0.4)
racc (1.7.3)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.2.2)
actionpack (= 7.0.2.2)
activesupport (= 7.0.2.2)
Expand Down Expand Up @@ -141,6 +163,11 @@ GEM
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
signet (0.18.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -154,10 +181,11 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
uri (0.13.0)
webpush (1.1.0)
hkdf (~> 0.2)
jwt (~> 2.0)
zeitwerk (2.5.4)
zeitwerk (2.6.12)

PLATFORMS
ruby
Expand Down
1 change: 1 addition & 0 deletions lib/generators/rpush_migration_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def copy_migration
add_rpush_migration('rpush_4_1_0_updates')
add_rpush_migration('rpush_4_1_1_updates')
add_rpush_migration('rpush_4_2_0_updates')
add_rpush_migration('rpush_7_1_0_updates')
end

protected
Expand Down
17 changes: 17 additions & 0 deletions lib/generators/templates/rpush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@
# on.tcp_connection_lost do |app, error|
# end

# Called for each recipient which successfully receives a notification. This
# can occur more than once for the same notification when there are multiple
# recipients.
# on.fcm_delivered_to_recipient do |notification|
# end

# Called for each recipient which fails to receive a notification. This
# can occur more than once for the same notification when there are multiple
# recipients. (do not handle invalid registration IDs here)
# on.fcm_failed_to_recipient do |notification, error|
# end

# Called when the FCM returns a failure that indicates an invalid device token.
# You will need to delete the device token from your records.
# on.fcm_invalid_device_token do |app, error, device_token|
# end

# Called for each recipient which successfully receives a notification. This
# can occur more than once for the same notification when there are multiple
# recipients.
Expand Down
12 changes: 12 additions & 0 deletions lib/generators/templates/rpush_7_1_0_updates.rb
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

1 change: 1 addition & 0 deletions lib/rpush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'active_support/all'
require 'net-http2'
require 'jwt'
require 'googleauth'

require 'rails'

Expand Down
5 changes: 5 additions & 0 deletions lib/rpush/client/active_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
require 'rpush/client/active_model/adm/app'
require 'rpush/client/active_model/adm/notification'

require 'rpush/client/active_model/fcm/expiry_collapse_key_mutual_inclusion_validator'
require 'rpush/client/active_model/fcm/notification_keys_in_allowed_list_validator'
require 'rpush/client/active_model/fcm/app'
require 'rpush/client/active_model/fcm/notification'

require 'rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator'
require 'rpush/client/active_model/gcm/app'
require 'rpush/client/active_model/gcm/notification'
Expand Down
20 changes: 20 additions & 0 deletions lib/rpush/client/active_model/fcm/app.rb
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
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
120 changes: 120 additions & 0 deletions lib/rpush/client/active_model/fcm/notification.rb
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
Loading

0 comments on commit 2706127

Please sign in to comment.