Skip to content

fix(fcm): Android Notification boolean parameters #370

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

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions firebase_admin/_messaging_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,6 @@ def encode_milliseconds(cls, label, msec):
return '{0}.{1}s'.format(seconds, str(nanos).zfill(9))
return '{0}s'.format(seconds)

@classmethod
def encode_boolean(cls, value):
"""Encodes a boolean into JSON."""
if value is None:
return None
return 1 if value else 0

@classmethod
def encode_android_notification(cls, notification):
"""Encodes an ``AndroidNotification`` instance into JSON."""
Expand Down Expand Up @@ -303,17 +296,17 @@ def encode_android_notification(cls, notification):
'image', notification.image),
'ticker': _Validators.check_string(
'AndroidNotification.ticker', notification.ticker),
'sticky': cls.encode_boolean(notification.sticky),
'sticky': notification.sticky,
'event_time': _Validators.check_datetime(
'AndroidNotification.event_timestamp', notification.event_timestamp),
'local_only': cls.encode_boolean(notification.local_only),
'local_only': notification.local_only,
'notification_priority': _Validators.check_string(
'AndroidNotification.priority', notification.priority, non_empty=True),
'vibrate_timings': _Validators.check_number_list(
'AndroidNotification.vibrate_timings_millis', notification.vibrate_timings_millis),
'default_vibrate_timings': cls.encode_boolean(notification.default_vibrate_timings),
'default_sound': cls.encode_boolean(notification.default_sound),
'default_light_settings': cls.encode_boolean(notification.default_light_settings),
'default_vibrate_timings': notification.default_vibrate_timings,
'default_sound': notification.default_sound,
'default_light_settings': notification.default_light_settings,
'light_settings': cls.encode_light_settings(notification.light_settings),
'visibility': _Validators.check_string(
'AndroidNotification.visibility', notification.visibility, non_empty=True),
Expand Down
2 changes: 1 addition & 1 deletion firebase_admin/_messaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AndroidNotification(object):
ticker: Sets the ``ticker`` text, which is sent to accessibility services. Prior to API
level 21 (Lollipop), sets the text that is displayed in the status bar when the
notification first arrives (optional).
sticky: When set to ``false`` or unset, the notification is automatically dismissed when the
sticky: When set to ``False`` or unset, the notification is automatically dismissed when the
user clicks it in the panel. When set to ``True``, the notification persists even when
the user clicks it (optional).
event_timestamp: For notifications that inform users about events with an absolute time
Expand Down
5 changes: 5 additions & 0 deletions integration/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def test_send():
priority='high',
vibrate_timings_millis=[100, 200, 300, 400],
visibility='public',
sticky=True,
local_only=False,
default_vibrate_timings=False,
default_sound=True,
default_light_settings=False,
light_settings=messaging.LightSettings(
color='#aabbcc',
light_off_duration_millis=200,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,12 @@ def test_android_notification(self):
'body_loc_args': ['b1', 'b2'],
'channel_id': 'c',
'ticker': 'ticker',
'sticky': 1,
'sticky': True,
'event_time': '2019-10-20T15:12:23.000123Z',
'local_only': 0,
'local_only': False,
'notification_priority': 'PRIORITY_HIGH',
'vibrate_timings': ['0.100000000s', '0.050000000s', '0.250000000s'],
'default_vibrate_timings': 0,
'default_vibrate_timings': False,
'default_sound': 1,
'light_settings': {
'color': {
Expand All @@ -594,7 +594,7 @@ def test_android_notification(self):
'light_on_duration': '0.200000000s',
'light_off_duration': '0.300000000s',
},
'default_light_settings': 0,
'default_light_settings': False,
'visibility': 'PUBLIC',
'notification_count': 1,
},
Expand Down