Repository navigation
Add FCM topics REST API #1260
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
ttypic
wants to merge
1
commit into
main
Choose a base branch
from
AIT-1450/fcm-topics
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.
+878
−13
Open
Add FCM topics REST API #1260
Changes from all commits
Commits
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
77 changes: 77 additions & 0 deletions
77
core-android/src/main/java/io/ably/pubsub/push/FcmTopic.java
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package io.ably.pubsub.push; | ||
|
|
||
| import io.ably.pubsub.http.HttpRequester; | ||
| import io.ably.pubsub.http.PubSubBase; | ||
| import io.ably.pubsub.realtime.CompletionListener; | ||
| import io.ably.pubsub.types.AblyException; | ||
|
|
||
| /** | ||
| * A single FCM topic that this device can subscribe to or unsubscribe from. | ||
| * Obtained from {@link FcmTopics#get(String)}. | ||
| */ | ||
| public class FcmTopic { | ||
| /** | ||
| * The FCM topic name. | ||
| */ | ||
| public final String name; | ||
|
|
||
| private final PubSubBase rest; | ||
| private final Push push; | ||
|
|
||
| FcmTopic(PubSubBase rest, Push push, String name) { | ||
| this.rest = rest; | ||
| this.push = push; | ||
| this.name = name; | ||
| } | ||
|
|
||
| /** | ||
| * Subscribes this device to the topic. Subscribing when already subscribed succeeds. | ||
| * <p> | ||
| * If FCM rejects the device's registration token, Ably marks the device registration failed | ||
| * and the request fails; the device must then activate again. | ||
| * | ||
| * @throws AblyException | ||
| */ | ||
| public void subscribe() throws AblyException { | ||
| subscribeImpl().sync(); | ||
| } | ||
|
|
||
| /** | ||
| * Asynchronously subscribes this device to the topic. See {@link #subscribe()}. | ||
| * | ||
| * @param listener A listener to be notified of success or failure. | ||
| * <p> | ||
| * This listener is invoked on a background thread. | ||
| */ | ||
| public void subscribeAsync(CompletionListener listener) { | ||
| subscribeImpl().async(new CompletionListener.ToCallback<>(listener)); | ||
| } | ||
|
|
||
| /** | ||
| * Unsubscribes this device from the topic. Unsubscribing when not subscribed succeeds. | ||
| * | ||
| * @throws AblyException | ||
| */ | ||
| public void unsubscribe() throws AblyException { | ||
| unsubscribeImpl().sync(); | ||
| } | ||
|
|
||
| /** | ||
| * Asynchronously unsubscribes this device from the topic. See {@link #unsubscribe()}. | ||
| * | ||
| * @param listener A listener to be notified of success or failure. | ||
| * <p> | ||
| * This listener is invoked on a background thread. | ||
| */ | ||
| public void unsubscribeAsync(CompletionListener listener) { | ||
| unsubscribeImpl().async(new CompletionListener.ToCallback<>(listener)); | ||
| } | ||
|
|
||
| private HttpRequester.Request<Void> subscribeImpl() { | ||
| return push.localDeviceRequest((deviceId, headers) -> AdminFcmTopics.subscribeDeviceImpl(rest, headers, name, deviceId)); | ||
| } | ||
|
|
||
| private HttpRequester.Request<Void> unsubscribeImpl() { | ||
| return push.localDeviceRequest((deviceId, headers) -> AdminFcmTopics.unsubscribeDeviceImpl(rest, headers, name, deviceId)); | ||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
core-android/src/main/java/io/ably/pubsub/push/FcmTopics.java
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package io.ably.pubsub.push; | ||
|
|
||
| import io.ably.pubsub.http.HttpRequester; | ||
| import io.ably.pubsub.http.PubSubBase; | ||
| import io.ably.pubsub.types.AblyException; | ||
| import io.ably.pubsub.types.Callback; | ||
|
|
||
| /** | ||
| * Manages this device's FCM topic subscriptions. | ||
| * <p> | ||
| * FCM topics let FCM fan a single send out to every device subscribed to the topic. A topic exists | ||
| * once its first device subscribes; there is no create or delete call. Topic names must match | ||
| * {@code [a-zA-Z0-9-_.~%]{1,900}}. FCM allows at most 2,000 topic subscriptions per device and never | ||
| * removes them automatically, so unsubscribe when the device no longer needs a topic. | ||
| * <p> | ||
| * The device must be activated for push with FCM ({@link Push#activate()} must have completed) before | ||
| * using these methods. Requests authenticate as the device, so no push-admin capability is needed. | ||
| */ | ||
| public class FcmTopics { | ||
| private final PubSubBase rest; | ||
| private final Push push; | ||
|
|
||
| FcmTopics(PubSubBase rest, Push push) { | ||
| this.rest = rest; | ||
| this.push = push; | ||
| } | ||
|
|
||
| /** | ||
| * Returns an {@link FcmTopic} for subscribing this device to, or unsubscribing it from, the named topic. | ||
| * An empty topic name is reported as an {@link AblyException} by the operations on the returned object. | ||
| * | ||
| * @param topic The FCM topic name. | ||
| * @return An {@link FcmTopic} object. | ||
| */ | ||
| public FcmTopic get(String topic) { | ||
| return new FcmTopic(rest, push, topic); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the names of the FCM topics this device is subscribed to, | ||
| * including any it subscribed to other than through Ably. | ||
| * | ||
| * @return The topic names. | ||
| * @throws AblyException | ||
| */ | ||
| public String[] list() throws AblyException { | ||
| return listImpl().sync(); | ||
| } | ||
|
|
||
| /** | ||
| * Asynchronously retrieves the names of the FCM topics this device is subscribed to, | ||
| * including any it subscribed to other than through Ably. | ||
| * | ||
| * @param callback A callback returning the topic names. | ||
| * <p> | ||
| * This callback is invoked on a background thread. | ||
| */ | ||
| public void listAsync(Callback<String[]> callback) { | ||
| listImpl().async(callback); | ||
| } | ||
|
|
||
| private HttpRequester.Request<String[]> listImpl() { | ||
| return push.localDeviceRequest((deviceId, headers) -> AdminFcmTopics.listImpl(rest, headers, deviceId)); | ||
| } | ||
| } |
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
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.
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.
Script executed:
Repository: ably/ably-pubsub-java
Length of output: 14687
Script executed:
Repository: ably/ably-pubsub-java
Length of output: 8013
Correct the
subscribe()recovery note: activating an active device does not re-register it.For an active device,
activate()only invokes the activated callback and keeps the current state. It does not validate the registration or send a registration request. Nothing on the failed topic subscribe path changes that state. Callingactivate()after a rejected subscribe therefore reports success. Later subscribes reuse the same identity token and may fail the same way.The Javadoc should describe this behavior accurately.
📝 Suggested Javadoc correction