Skip to content

Firebase Cloud Messaging API - #187

Merged
hiranya911 merged 26 commits into
masterfrom
hkj-fcm-api
Feb 13, 2018
Merged

Firebase Cloud Messaging API#187
hiranya911 merged 26 commits into
masterfrom
hkj-fcm-api

Conversation

@hiranya911

Copy link
Copy Markdown
Contributor

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

go/firebase-admin-fcm-api

Comment threadtest/integration/messaging.spec.ts Outdated
body: 'Message body',
},
android: {
restrictedPackageName: 'com.hkj.testing'

@avishalomavishalomJan 31, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@bojeil-googlebojeil-google left a comment

Copy link
Copy Markdown
Contributor

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.

return null;
}

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done


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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

Comment threadsrc/messaging/messaging.ts Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

Comment threadsrc/messaging/messaging.ts Outdated
}
}
if (validator.isNonEmptyArray(apsAlert.titleLocArgs)) {
if (!validator.isNonEmptyString(apsAlert.titleLocKey)) {

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

Comment threadsrc/messaging/messaging.ts Outdated
MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.color must be in the form #RRGGBB');
}
if (validator.isNonEmptyArray(notification.bodyLocArgs)) {
if (!validator.isNonEmptyString(notification.bodyLocKey)) {

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

Comment threadsrc/messaging/messaging.ts Outdated
}
}
if (validator.isNonEmptyArray(notification.titleLocArgs)) {
if (!validator.isNonEmptyString(notification.titleLocKey)) {

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@bojeil-googlebojeil-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 masterFeb 13, 2018
@hiranya911
hiranya911 deleted the hkj-fcm-api branch February 13, 2018 02:24
Sign up for freeto 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.

3 participants

@hiranya911@avishalom@bojeil-google