-
Notifications
You must be signed in to change notification settings - Fork 378
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
Conversation
test/integration/messaging.spec.ts
Outdated
body: 'Message body', | ||
}, | ||
android: { | ||
restrictedPackageName: 'com.hkj.testing' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define javadoc for this.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/messaging/messaging.ts
Outdated
titleLocArgs?: string[]; | ||
} | ||
|
||
function validateStringMap(map: object, label: string) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/messaging/messaging.ts
Outdated
|
||
const apsAlert: ApsAlert = alert as ApsAlert; | ||
if (validator.isNonEmptyArray(apsAlert.locArgs)) { | ||
if (!validator.isNonEmptyString(apsAlert.locKey)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/messaging/messaging.ts
Outdated
} | ||
} | ||
if (validator.isNonEmptyArray(apsAlert.titleLocArgs)) { | ||
if (!validator.isNonEmptyString(apsAlert.titleLocKey)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/messaging/messaging.ts
Outdated
} | ||
} | ||
if (validator.isNonEmptyArray(notification.titleLocArgs)) { | ||
if (!validator.isNonEmptyString(notification.titleLocKey)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* Accept prefixed topic names * Further validating topic names
* Using new FCM error codes * Adding new SDK error code message-rate-exceeded
Implements the
admin.messaging.send()
operation based on the new FCM server API.go/firebase-admin-fcm-api