-
Notifications
You must be signed in to change notification settings - Fork 416
feat(fcm): Enable fid and deprecate token for Send API
#3145
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
Open
yvonnep165
wants to merge
12
commits into
main
Choose a base branch
from
yp-add-fid-arg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9846af3
Add FidMessage and deprecate TokenMessage
yvonnep165 97ac410
Add fids to MulticastMessage interface
yvonnep165 7bdf972
Add integration tests
yvonnep165 8b5e564
Extract API docstring
yvonnep165 208378e
Merge branch 'main' into yp-add-fid-arg
yvonnep165 96de332
Change tokens back to required field, add extra docstrings and refact…
yvonnep165 ec3fdc4
Fix the lint error
yvonnep165 6986cc7
Merge branch 'main' into yp-add-fid-arg
yvonnep165 37b2740
Merge branch 'main' into yp-add-fid-arg
yvonnep165 cf2163d
Add FidMulticastMessage and Implement Function Overloads on sendEachF…
yvonnep165 da81dc2
Extract API doc and remove hyperlink due to duplicate names from func…
yvonnep165 d914462
Update sendEachForMulticast docstring
yvonnep165 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import { FirebaseMessagingRequestHandler } from './messaging-api-request-interna | |
|
|
||
| import { | ||
| BatchResponse, | ||
| FidMulticastMessage, | ||
| Message, | ||
| MessagingTopicManagementResponse, | ||
| MulticastMessage, | ||
|
|
@@ -274,50 +275,83 @@ export class Messaging { | |
| } | ||
|
|
||
| /** | ||
| * Sends the given multicast message to all the FCM registration tokens | ||
| * Sends the given multicast message to all the FCM registration tokens or fids | ||
| * specified in it. | ||
| * | ||
| * This method uses the {@link Messaging.sendEach} API under the hood to send the given | ||
| * message to all the target recipients. The responses list obtained from the | ||
| * return value corresponds to the order of tokens in the `MulticastMessage`. | ||
| * return value corresponds to the order of tokens/fids in the `MulticastMessage`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Maybe clarify that
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, added! |
||
| * If both `tokens` and `fids` are provided, `tokens` are processed first, followed by `fids`. | ||
| * An error from this method or a `BatchResponse` with all failures indicates a total | ||
| * failure, meaning that the messages in the list could be sent. Partial failures or | ||
| * failures are only indicated by a `BatchResponse` return value. | ||
| * failure, meaning that the messages in the list could not be sent. Partial failures | ||
| * are only indicated by a `BatchResponse` return value. | ||
| * | ||
| * @param message - A multicast message | ||
| * containing up to 500 tokens. | ||
| * @deprecated Use the overload accepting {@link FidMulticastMessage} instead. | ||
| * | ||
| * @param message - A multicast message containing up to 500 tokens and/or fids. | ||
| * @param dryRun - Whether to send the message in the dry-run | ||
| * (validation only) mode. | ||
| * @returns A Promise fulfilled with an object representing the result of the | ||
| * send operation. | ||
| */ | ||
| public sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse> { | ||
| const copy: MulticastMessage = deepCopy(message); | ||
| public sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>; | ||
|
|
||
| /** | ||
| * Sends the given multicast message to all the FCM fids specified in it. | ||
| * | ||
| * This method uses the {@link Messaging.sendEach} API under the hood to send the given | ||
| * message to all the target recipients. The responses list obtained from the | ||
| * return value corresponds to the order of fids in the `FidMulticastMessage`. | ||
| * An error from this method or a `BatchResponse` with all failures indicates a total | ||
| * failure, meaning that the messages in the list could not be sent. Partial failures | ||
| * are only indicated by a `BatchResponse` return value. | ||
| * | ||
| * @param message - A multicast message containing up to 500 fids. | ||
| * @param dryRun - Whether to send the message in the dry-run (validation only) mode. | ||
| * @returns A Promise fulfilled with an object representing the result of the send operation. | ||
| */ | ||
| public sendEachForMulticast(message: FidMulticastMessage, dryRun?: boolean): Promise<BatchResponse>; | ||
|
|
||
| public sendEachForMulticast( | ||
| message: MulticastMessage | FidMulticastMessage, | ||
| dryRun?: boolean, | ||
| ): Promise<BatchResponse> { | ||
| const copy: any = deepCopy(message); | ||
| if (!validator.isNonNullObject(copy)) { | ||
| throw new FirebaseMessagingError( | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, 'MulticastMessage must be a non-null object'); | ||
| } | ||
| if (!validator.isNonEmptyArray(copy.tokens)) { | ||
|
|
||
| const { tokens, fids, ...baseMessage } = copy; | ||
|
|
||
| const tokenList: string[] = tokens || []; | ||
| const fidList: string[] = fids || []; | ||
|
|
||
| if ('tokens' in copy && !validator.isArray(copy.tokens)) { | ||
| throw new FirebaseMessagingError( | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, 'tokens must be a valid array'); | ||
| } | ||
| if ('fids' in copy && !validator.isArray(copy.fids)) { | ||
| throw new FirebaseMessagingError( | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, 'tokens must be a non-empty array'); | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, 'fids must be a valid array'); | ||
| } | ||
| if (copy.tokens.length > FCM_MAX_BATCH_SIZE) { | ||
| if (tokenList.length === 0 && fidList.length === 0) { | ||
| throw new FirebaseMessagingError( | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, 'Either tokens or fids must be a non-empty array'); | ||
| } | ||
|
|
||
| const totalLength = tokenList.length + fidList.length; | ||
| if (totalLength > FCM_MAX_BATCH_SIZE) { | ||
| throw new FirebaseMessagingError( | ||
| MessagingClientErrorCode.INVALID_ARGUMENT, | ||
| `tokens list must not contain more than ${FCM_MAX_BATCH_SIZE} items`); | ||
| `The total number of tokens and fids must not exceed ${FCM_MAX_BATCH_SIZE}.`); | ||
| } | ||
|
|
||
| const messages: Message[] = copy.tokens.map((token) => { | ||
| return { | ||
| token, | ||
| android: copy.android, | ||
| apns: copy.apns, | ||
| data: copy.data, | ||
| notification: copy.notification, | ||
| webpush: copy.webpush, | ||
| fcmOptions: copy.fcmOptions, | ||
| }; | ||
| }); | ||
| const messages: Message[] = [ | ||
| ...tokenList.map((token) => ({ ...baseMessage, token } as Message)), | ||
| ...fidList.map((fid) => ({ ...baseMessage, fid } as Message)), | ||
| ]; | ||
|
|
||
| return this.sendEach(messages, dryRun); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.