Skip to content
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

Firebase Cloud Messaging API #187

Merged
merged 26 commits into from
Feb 13, 2018
Merged

Firebase Cloud Messaging API #187

merged 26 commits into from
Feb 13, 2018

Conversation

hiranya911
Copy link
Contributor

Implements the admin.messaging.send() operation based on the new FCM server API.

go/firebase-admin-fcm-api

body: 'Message body',
},
android: {
restrictedPackageName: 'com.hkj.testing'
Copy link
Contributor

@avishalom avishalom Jan 31, 2018

Choose a reason for hiding this comment

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

hkj is not in the codebase yet, maybe put something generic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@bojeil-google bojeil-google left a comment

Choose a reason for hiding this comment

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

Mostly nits. Would recommend someone on FCM team to take another look.

@@ -53,6 55,15 @@ export class FirebaseMessagingRequestHandler {
return null;
}

private static getErrorMessage(response: any): string | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

Define javadoc for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -53,6 55,15 @@ export class FirebaseMessagingRequestHandler {
return null;
}

private static getErrorMessage(response: any): string | null {
if (validator.isNonNullObject(response) && 'error' in response) {
if (validator.isNonEmptyString(response.error.message)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can group the 2 nested if statements in one.

if (validator.isNonNullObject(response) &&
    'error' in response &&
    validator.isNonEmptyString(response.error.message) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

titleLocArgs?: string[];
}

function validateStringMap(map: object, label: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding javadoc descriptions for all these functions in this file to be consistent with existing convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


const apsAlert: ApsAlert = alert as ApsAlert;
if (validator.isNonEmptyArray(apsAlert.locArgs)) {
if (!validator.isNonEmptyString(apsAlert.locKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, the 2 nested if statements can be grouped into 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}
if (validator.isNonEmptyArray(apsAlert.titleLocArgs)) {
if (!validator.isNonEmptyString(apsAlert.titleLocKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, the 2 nested if statements can be grouped into 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification must be a non-null object');
}

if (typeof notification.color !== 'undefined' && !/^#[0-9a-fA-F]{6}$/.test(notification.color)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a color validator is useful to add to our validator class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now this is the only place where we do this specific validation. So I'll keep it as is for now.

MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.color must be in the form #RRGGBB');
}
if (validator.isNonEmptyArray(notification.bodyLocArgs)) {
if (!validator.isNonEmptyString(notification.bodyLocKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nested if statements can be grouped to 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}
if (validator.isNonEmptyArray(notification.titleLocArgs)) {
if (!validator.isNonEmptyString(notification.titleLocKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nested if statements can be grouped to 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.then(() => {
expect(requestWriteSpy).to.have.been.calledOnce;
const requestData = JSON.parse(requestWriteSpy.args[0][0]);
const want = config.want || config.req;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: maybe call it expectedServerReq or expectedReq or something of the like, instead of want ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bojeil-google bojeil-google removed their assignment Feb 3, 2018
* Accept prefixed topic names

* Further validating topic names
* Using new FCM error codes

* Adding new SDK error code message-rate-exceeded
@hiranya911 hiranya911 merged commit f42518f into master Feb 13, 2018
@hiranya911 hiranya911 deleted the hkj-fcm-api branch February 13, 2018 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants