Skip to content

feat(messaging): migrate topic management to FCM v1 REST API - #327

Merged
demolaf merged 3 commits into
mainfrom
lm-fcm-topics
Sep 29, 2026
Merged

demolaf merged 3 commits into
mainfrom
lm-fcm-topics

Conversation

@lahirumaramba

Copy link
Copy Markdown
Member

Description

  • Migrate subscribeToTopic and unsubscribeFromTopic to FCM v1 REST API.
  • Concurrently process registration token requests with a worker pool (up to 100 concurrent requests).
  • Add deprecated subscribeToTopicLegacy and unsubscribeFromTopicLegacy methods for backward compatibility with the IID API.
  • Validate registration tokens list length (up to 1000 tokens) and topic format.
  • Handle 409 Conflict / ALREADY_EXISTS responses as success during subscription.
  • Update unit tests covering FCM v1 topic management endpoints, error handling, and legacy methods.
  • Update CHANGELOG.md.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request migrates FCM topic management (subscribeToTopic and unsubscribeFromTopic) to the FCM v1 REST API, deprecating the legacy IID methods. It introduces concurrent worker processing for token subscriptions and adds a 1000-token limit validation. Feedback on the changes highlights a potential double-encoding issue when constructing request URIs with pre-encoded path components, recommending the use of Uri with pathSegments instead. Additionally, the topic validation regex incorrectly allows a private/ segment, which contradicts the error message and is unsupported by the FCM v1 REST API.

Comment thread packages/firebase_admin_sdk/lib/src/messaging/messaging_request_handler.dart Outdated
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Coverage Report

✅ Coverage 74.34% meets 40% threshold

Total Coverage: 74.34%
Lines Covered: 6116/8227

Package Breakdown

Package Coverage
firebase_admin_sdk 73.95%
google_cloud_firestore 74.69%

Minimum threshold: 40%

@lahirumaramba
lahirumaramba marked this pull request as ready for review September 21, 2026 19:45
@lahirumaramba

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request migrates FCM topic management (subscribeToTopic and unsubscribeFromTopic) from the legacy IID API to the FCM v1 REST API, while deprecating the legacy methods as subscribeToTopicLegacy and unsubscribeFromTopicLegacy. The migration introduces concurrent requests using a worker pool, adds validation for a maximum of 1000 registration tokens, and updates topic format validation. Comprehensive unit tests have been added to verify the new REST API integrations, error handling, and legacy methods. There are no review comments to address, and no additional feedback is provided.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request migrates FCM topic management (subscribeToTopic and unsubscribeFromTopic) from the legacy IID API to the FCM v1 REST API, while deprecating the legacy methods as subscribeToTopicLegacy and unsubscribeFromTopicLegacy. The new implementation processes registration tokens concurrently using a worker pool to interact with the FCM v1 REST API, adds validation to limit registration tokens to 1000, and updates error handling and unit tests accordingly. There are no review comments provided, and I have no additional feedback on these changes.

@demolaf demolaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two notes. The CHANGELOG one blocks; the allow_missing one is a question rather than a change request.

Comment thread packages/firebase_admin_sdk/CHANGELOG.md Outdated
'topicSubscriptions',
cleanTopic,
],
queryParameters: {'allow_missing': 'true'},

@demolaf demolaf Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does allow_missing=true also suppress NOT_FOUND when the token itself is unregistered? Legacy batchRemove reported those as per-token failures, so suppressing them would drop a signal callers may rely on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm good question. It should not suppress NOT_FOUND when the token itself is unregistered.

Per Google API AIP-135, allow_missing=true only applies to the leaf resource being deleted (topicSubscriptions/{cleanTopic}). When the registration token is not registered, the parent resource (registrations/{token}) does not exist, and the FCM v1 endpoint still returns HTTP 404 NOT_FOUND.

The SDK maps that 404 to MessagingClientErrorCode.registrationTokenNotRegistered, preserving the per-token failure signal just like legacy batchRemove. What allow_missing=true does is make unsubscription idempotent when the token is valid/registered but was never subscribed to that topic (avoiding a false failure for an already-unsubscribed token).

@demolaf demolaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@lahirumaramba can you apply the fix to CHANGELOG here too?

- Migrate subscribeToTopic and unsubscribeFromTopic to FCM v1 REST API.
- Concurrently process registration token requests with a worker pool (up to 100 concurrent requests).
- Add deprecated subscribeToTopicLegacy and unsubscribeFromTopicLegacy methods for backward compatibility with the IID API.
- Validate registration tokens list length (up to 1000 tokens) and topic format.
- Handle 409 Conflict / ALREADY_EXISTS responses as success during subscription.
- Update unit tests covering FCM v1 topic management endpoints, error handling, and legacy methods.
- Update CHANGELOG.md.
- Use Uri constructor with pathSegments instead of Uri.https with pre-encoded components to prevent double-encoding.
- Remove (private/)? from topic validation regex to match FCM v1 API and error format.
- Add invalid topic test cases for paths containing slashes.
@demolaf
demolaf merged commit b388aed into main Sep 29, 2026
21 checks passed
@demolaf
demolaf deleted the lm-fcm-topics branch September 29, 2026 11:27
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.

3 participants