Skip to content

Commit 2e67b96

Browse files
Fix FCM Android Notification boolean parameters (#370)
1 parent 24e5ad4 commit 2e67b96

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

firebase_admin/_messaging_encoder.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,6 @@ def encode_milliseconds(cls, label, msec):
259259
return '{0}.{1}s'.format(seconds, str(nanos).zfill(9))
260260
return '{0}s'.format(seconds)
261261

262-
@classmethod
263-
def encode_boolean(cls, value):
264-
"""Encodes a boolean into JSON."""
265-
if value is None:
266-
return None
267-
return 1 if value else 0
268-
269262
@classmethod
270263
def encode_android_notification(cls, notification):
271264
"""Encodes an ``AndroidNotification`` instance into JSON."""
@@ -303,17 +296,17 @@ def encode_android_notification(cls, notification):
303296
'image', notification.image),
304297
'ticker': _Validators.check_string(
305298
'AndroidNotification.ticker', notification.ticker),
306-
'sticky': cls.encode_boolean(notification.sticky),
299+
'sticky': notification.sticky,
307300
'event_time': _Validators.check_datetime(
308301
'AndroidNotification.event_timestamp', notification.event_timestamp),
309-
'local_only': cls.encode_boolean(notification.local_only),
302+
'local_only': notification.local_only,
310303
'notification_priority': _Validators.check_string(
311304
'AndroidNotification.priority', notification.priority, non_empty=True),
312305
'vibrate_timings': _Validators.check_number_list(
313306
'AndroidNotification.vibrate_timings_millis', notification.vibrate_timings_millis),
314-
'default_vibrate_timings': cls.encode_boolean(notification.default_vibrate_timings),
315-
'default_sound': cls.encode_boolean(notification.default_sound),
316-
'default_light_settings': cls.encode_boolean(notification.default_light_settings),
307+
'default_vibrate_timings': notification.default_vibrate_timings,
308+
'default_sound': notification.default_sound,
309+
'default_light_settings': notification.default_light_settings,
317310
'light_settings': cls.encode_light_settings(notification.light_settings),
318311
'visibility': _Validators.check_string(
319312
'AndroidNotification.visibility', notification.visibility, non_empty=True),

firebase_admin/_messaging_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class AndroidNotification(object):
9393
ticker: Sets the ``ticker`` text, which is sent to accessibility services. Prior to API
9494
level 21 (Lollipop), sets the text that is displayed in the status bar when the
9595
notification first arrives (optional).
96-
sticky: When set to ``false`` or unset, the notification is automatically dismissed when the
96+
sticky: When set to ``False`` or unset, the notification is automatically dismissed when the
9797
user clicks it in the panel. When set to ``True``, the notification persists even when
9898
the user clicks it (optional).
9999
event_timestamp: For notifications that inform users about events with an absolute time

integration/test_messaging.py

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def test_send():
4545
priority='high',
4646
vibrate_timings_millis=[100, 200, 300, 400],
4747
visibility='public',
48+
sticky=True,
49+
local_only=False,
50+
default_vibrate_timings=False,
51+
default_sound=True,
52+
default_light_settings=False,
4853
light_settings=messaging.LightSettings(
4954
color='#aabbcc',
5055
light_off_duration_millis=200,

tests/test_messaging.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@ def test_android_notification(self):
577577
'body_loc_args': ['b1', 'b2'],
578578
'channel_id': 'c',
579579
'ticker': 'ticker',
580-
'sticky': 1,
580+
'sticky': True,
581581
'event_time': '2019-10-20T15:12:23.000123Z',
582-
'local_only': 0,
582+
'local_only': False,
583583
'notification_priority': 'PRIORITY_HIGH',
584584
'vibrate_timings': ['0.100000000s', '0.050000000s', '0.250000000s'],
585-
'default_vibrate_timings': 0,
585+
'default_vibrate_timings': False,
586586
'default_sound': 1,
587587
'light_settings': {
588588
'color': {
@@ -594,7 +594,7 @@ def test_android_notification(self):
594594
'light_on_duration': '0.200000000s',
595595
'light_off_duration': '0.300000000s',
596596
},
597-
'default_light_settings': 0,
597+
'default_light_settings': False,
598598
'visibility': 'PUBLIC',
599599
'notification_count': 1,
600600
},

0 commit comments

Comments
 (0)