From 378ac1b5603f79301b05ca297cdf43a8d9a56b86 Mon Sep 17 00:00:00 2001 From: Cham Date: Wed, 21 Aug 2019 12:01:45 +0800 Subject: [PATCH 1/5] Add "image" field to AndroidNotification and Notification --- firebase_admin/_messaging_utils.py | 12 ++++++++++-- integration/test_messaging.py | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index 72e2acab3..1887f00bb 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -89,11 +89,13 @@ class Notification(object): Args: title: Title of the notification (optional). body: Body of the notification (optional). + image: Image url of the notification (optional) """ - def __init__(self, title=None, body=None): + def __init__(self, title=None, body=None, image=None): self.title = title self.body = body + self.image = image class AndroidConfig(object): @@ -153,11 +155,12 @@ class AndroidNotification(object): title_loc_args: A list of resource keys that will be used in place of the format specifiers in ``title_loc_key`` (optional). channel_id: channel_id of the notification (optional). + image: Image url of the notification (optional). """ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag=None, click_action=None, body_loc_key=None, body_loc_args=None, title_loc_key=None, - title_loc_args=None, channel_id=None): + title_loc_args=None, channel_id=None, image=None): self.title = title self.body = body self.icon = icon @@ -170,6 +173,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag self.title_loc_key = title_loc_key self.title_loc_args = title_loc_args self.channel_id = channel_id + self.image = image class AndroidFCMOptions(object): @@ -600,6 +604,9 @@ def encode_android_notification(cls, notification): 'AndroidNotification.title_loc_key', notification.title_loc_key), 'channel_id': _Validators.check_string( 'AndroidNotification.channel_id', notification.channel_id), + 'image': _Validators.check_string( + 'image', notification.image + ) } result = cls.remove_null_values(result) color = result.get('color') @@ -858,6 +865,7 @@ def encode_notification(cls, notification): result = { 'body': _Validators.check_string('Notification.body', notification.body), 'title': _Validators.check_string('Notification.title', notification.title), + 'image': _Validators.check_string('Notification.image', notification.image) } return cls.remove_null_values(result) diff --git a/integration/test_messaging.py b/integration/test_messaging.py index 7ebd5866a..29a2df72b 100644 --- a/integration/test_messaging.py +++ b/integration/test_messaging.py @@ -27,12 +27,14 @@ def test_send(): msg = messaging.Message( topic='foo-bar', - notification=messaging.Notification('test-title', 'test-body'), + notification=messaging.Notification('test-title', 'test-body', 'https://images.unsplash.com/photo-1494438639946' + '-1ebd1d20bf85?fit=crop&w=900&q=60'), android=messaging.AndroidConfig( restricted_package_name='com.google.firebase.demos', notification=messaging.AndroidNotification( title='android-title', - body='android-body' + body='android-body', + image='https://images.unsplash.com/photo-1494438639946-1ebd1d20bf85?fit=crop&w=900&q=60' ) ), apns=messaging.APNSConfig(payload=messaging.APNSPayload( From be85aa45064981f9c4e545665f00e104a4d32d8c Mon Sep 17 00:00:00 2001 From: Cham Date: Wed, 21 Aug 2019 13:17:47 +0800 Subject: [PATCH 2/5] Add Doc String to _messaging_utils.encode_notification --- firebase_admin/_messaging_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index 1887f00bb..cc0236746 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -858,6 +858,7 @@ def encode_aps_alert(cls, alert): @classmethod def encode_notification(cls, notification): + """Encodes an Notification instance into JSON.""" if notification is None: return None if not isinstance(notification, Notification): From 93f0550800e83aebe0d86a37250797da84c2ac72 Mon Sep 17 00:00:00 2001 From: Cham Date: Mon, 26 Aug 2019 15:06:03 +0800 Subject: [PATCH 3/5] Shorten Line Width --- integration/test_messaging.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/integration/test_messaging.py b/integration/test_messaging.py index 29a2df72b..b1caa09f9 100644 --- a/integration/test_messaging.py +++ b/integration/test_messaging.py @@ -27,14 +27,16 @@ def test_send(): msg = messaging.Message( topic='foo-bar', - notification=messaging.Notification('test-title', 'test-body', 'https://images.unsplash.com/photo-1494438639946' - '-1ebd1d20bf85?fit=crop&w=900&q=60'), + notification=messaging.Notification('test-title', 'test-body', + 'https://images.unsplash.com/photo-1494438639946' + '-1ebd1d20bf85?fit=crop&w=900&q=60'), android=messaging.AndroidConfig( restricted_package_name='com.google.firebase.demos', notification=messaging.AndroidNotification( title='android-title', body='android-body', - image='https://images.unsplash.com/photo-1494438639946-1ebd1d20bf85?fit=crop&w=900&q=60' + image='https://images.unsplash.com/' + 'photo-1494438639946-1ebd1d20bf85?fit=crop&w=900&q=60' ) ), apns=messaging.APNSConfig(payload=messaging.APNSPayload( From 56e06e04b71874af3e0f9f4e9da9117ccf8f055d Mon Sep 17 00:00:00 2001 From: Cham Date: Tue, 10 Sep 2019 12:26:57 +0800 Subject: [PATCH 4/5] Add "image" field to APNSFCMOptions. --- firebase_admin/_messaging_utils.py | 5 ++++- tests/test_messaging.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index cc0236746..435027f6f 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -423,10 +423,12 @@ class APNSFCMOptions(object): Args: analytics_label: contains additional options for features provided by the FCM iOS SDK (optional). + image: contains the URL of an image that is going to be displayed in a notification (optional). """ - def __init__(self, analytics_label=None): + def __init__(self, analytics_label=None, image=None): self.analytics_label = analytics_label + self.image = image class FCMOptions(object): @@ -761,6 +763,7 @@ def encode_apns_fcm_options(cls, fcm_options): result = { 'analytics_label': _Validators.check_analytics_label( 'APNSFCMOptions.analytics_label', fcm_options.analytics_label), + 'image': _Validators.check_string('APNSFCMOptions.image', fcm_options.image) } result = cls.remove_null_values(result) return result diff --git a/tests/test_messaging.py b/tests/test_messaging.py index 0b8739195..4f7520045 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -197,13 +197,19 @@ def test_fcm_options(self): fcm_options=messaging.FCMOptions('message-label'), android=messaging.AndroidConfig( fcm_options=messaging.AndroidFCMOptions('android-label')), - apns=messaging.APNSConfig(fcm_options=messaging.APNSFCMOptions('apns-label')) + apns=messaging.APNSConfig(fcm_options= + messaging.APNSFCMOptions( + analytics_label='apns-label', + image='https://images.unsplash.com/photo-14944386399' + '46-1ebd1d20bf85?fit=crop&w=900&q=60')) ), { 'topic': 'topic', 'fcm_options': {'analytics_label': 'message-label'}, 'android': {'fcm_options': {'analytics_label': 'android-label'}}, - 'apns': {'fcm_options': {'analytics_label': 'apns-label'}}, + 'apns': {'fcm_options': {'analytics_label': 'apns-label', + 'image': 'https://images.unsplash.com/photo-14944386399' + '46-1ebd1d20bf85?fit=crop&w=900&q=60'}}, }) From 9669196f19abe0a6a8ca1e91bd235be3b269fbad Mon Sep 17 00:00:00 2001 From: Cham Date: Tue, 10 Sep 2019 12:37:57 +0800 Subject: [PATCH 5/5] APNSFCMOptions: Shorten line --- firebase_admin/_messaging_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index 435027f6f..34738b168 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -423,7 +423,8 @@ class APNSFCMOptions(object): Args: analytics_label: contains additional options for features provided by the FCM iOS SDK (optional). - image: contains the URL of an image that is going to be displayed in a notification (optional). + image: contains the URL of an image that is going to be displayed in a notification + (optional). """ def __init__(self, analytics_label=None, image=None):