Skip to content

feat(fcm): Add 12 new Android Notification Parameters Support #363

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 6 commits into from
Nov 13, 2019

Conversation

lahirumaramba
Copy link
Member

Discussion

  • Introduce support for the new Android notification parameters in FCM API to AdminSDK.

Testing

  • Added unit tests and integration tests to reflect this change.

API Changes

  • In Messaging added new fields to AndroidNotification class.
  • Introduced LightSettings class

RELEASE NOTE: Added a series of new parameters to the AndroidNotification class that allow further customization of notifications that target Android devices.

@lahirumaramba
Copy link
Member Author

@hiranya911 :
I moved Message and MulticastMessage to the new _mesaage_encoder.py for now to avoid circular dependencies. I hope this is okay for now.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good. Just a few clarifications needed in the docs, plus a few readability improvements.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty solid. Just a few nits from me, and then I'll be at an LGTM.

@pytest.mark.parametrize('data', NON_STRING_ARGS + ['', 'topic', 'priority', 'foo'])
def test_invalid_visibility(self, data):
notification = messaging.AndroidNotification(visibility=data)
@pytest.mark.parametrize('visibility', NON_STRING_ARGS + ['', 'topic', 'priority', 'foo'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove topic and priority

@@ -32,6 +32,7 @@
NON_DICT_ARGS = ['', list(), tuple(), True, False, 1, 0, {1: 'foo'}, {'foo': 1}]
NON_OBJECT_ARGS = [list(), tuple(), dict(), 'foo', 0, 1, True, False]
NON_LIST_ARGS = ['', tuple(), dict(), True, False, 1, 0, [1], ['foo', 1]]
NON_UNUM_ARGS = ['1.23s', list(), tuple(), dict(), -1.23]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: NON_UINT_ARGS?

result = {
'color': _Validators.check_string(
'LightSettings.color', light_settings.color, non_empty=True),
'light_on_duration': cls.encode_milliseconds(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. But let's just document it as a milliseconds API for simplicity.

class _Validators(object):
"""A collection of data validation utilities.

Methods provided in this class raise ValueErrors if any validations fail.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a literal Lahiru? If so, let's code-font it (with backticks probably).



class MessageEncoder(json.JSONEncoder):
"""A custom JSONEncoder implementation for serializing Message instances into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be capped? I'm thinking not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I think JSONEncoder is correct here. I will code-font it. These were from one of our existing modules (not new code) they appear here as new because I had moved them to a new module file. It is good to fix the code-fonts though! :)


@classmethod
def encode_android_fcm_options(cls, fcm_options):
"""Encodes an AndroidFCMOptions instance into a json."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a literal.


@classmethod
def encode_android_fcm_options(cls, fcm_options):
"""Encodes an AndroidFCMOptions instance into a json."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be either "a JSON object" or maybe just "JSON?" Unless json is actually a literal.


@classmethod
def encode_ttl(cls, ttl):
"""Encodes a AndroidConfig TTL duration into a string."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"an AndroidConfig (if literal)


@classmethod
def encode_android_notification(cls, notification):
"""Encodes an AndroidNotification instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?


@classmethod
def encode_webpush_notification_actions(cls, actions):
"""Encodes a list of WebpushNotificationActions into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal? If not, then "Web Push notification actions" could even work.


@classmethod
def encode_webpush_fcm_options(cls, options):
"""Encodes a WebpushFCMOptions instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?


@classmethod
def encode_apns(cls, apns):
"""Encodes an APNSConfig instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?


@classmethod
def encode_apns_fcm_options(cls, fcm_options):
"""Encodes an APNSFCMOptions instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?


@classmethod
def encode_notification(cls, notification):
"""Encodes an Notification instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest "a notification"


@classmethod
def encode_fcm_options(cls, fcm_options):
"""Encodes an FCMOptions instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?


@classmethod
def encode_aps_alert(cls, alert):
"""Encodes an ApsAlert instance into JSON."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literal?

reference, sets the time that the event in the notification occurred as a
``datetime.datetime`` instance. Notifications in the panel are sorted by this time
(optional).
local_only: Set whether or not this notification is relevant only to the current device.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest sticking with "Sets"

watch. This hint can be set to recommend this notification not be bridged (optional).
See Wear OS guides:
https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging
priority: Set the relative priority for this notification. Low-priority notifications may be

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too: "Sets"

Copy link

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lahiru!

A couple of global thoughts:

-- Where we refer to literals, those should be code-fonted, with double backticks if that's what works with our Python doc parsing.
-- Total nit, but for setters we may want to stick with "Sets" whenever we are talking about a single method or property.

I tried but may not have caught all these nits.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hiranya911 hiranya911 removed their assignment Nov 12, 2019
Copy link

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lahiru!

Copy link

@chong-shao chong-shao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@lahirumaramba lahirumaramba merged commit 8580361 into master Nov 13, 2019
@lahirumaramba lahirumaramba deleted the lm-fcm-android-12 branch November 13, 2019 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants