Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/main/java/com/google/firebase/messaging/FirebaseMessaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,42 @@ private CallableOperation<TopicManagementResponse, FirebaseMessagingException> s
final List<String> registrationTokens, final String topic) {
checkRegistrationTokens(registrationTokens);
checkTopic(topic);
final FirebaseMessagingClient messagingClient = getMessagingClient();
return new CallableOperation<TopicManagementResponse, FirebaseMessagingException>() {
@Override
protected TopicManagementResponse execute() throws FirebaseMessagingException {
return messagingClient.subscribeToTopic(topic, registrationTokens);
}
};
}

/**
* Subscribes a list of registration tokens to a topic using the legacy Instance ID API.
*
* @deprecated Use {@link #subscribeToTopic(List, String)} instead.
*/
@Deprecated
public TopicManagementResponse subscribeToTopicLegacy(@NonNull List<String> registrationTokens,
@NonNull String topic) throws FirebaseMessagingException {
return subscribeLegacyOp(registrationTokens, topic).call();
}

/**
* Similar to {@link #subscribeToTopicLegacy(List, String)} but performs the operation
* asynchronously.
*
* @deprecated Use {@link #subscribeToTopicAsync(List, String)} instead.
*/
@Deprecated
public ApiFuture<TopicManagementResponse> subscribeToTopicLegacyAsync(
@NonNull List<String> registrationTokens, @NonNull String topic) {
return subscribeLegacyOp(registrationTokens, topic).callAsync(app);
}

private CallableOperation<TopicManagementResponse, FirebaseMessagingException> subscribeLegacyOp(
final List<String> registrationTokens, final String topic) {
checkRegistrationTokens(registrationTokens);
checkTopic(topic);
final InstanceIdClient instanceIdClient = getInstanceIdClient();
return new CallableOperation<TopicManagementResponse, FirebaseMessagingException>() {
@Override
Expand Down Expand Up @@ -597,6 +633,43 @@ private CallableOperation<TopicManagementResponse, FirebaseMessagingException> u
final List<String> registrationTokens, final String topic) {
checkRegistrationTokens(registrationTokens);
checkTopic(topic);
final FirebaseMessagingClient messagingClient = getMessagingClient();
return new CallableOperation<TopicManagementResponse, FirebaseMessagingException>() {
@Override
protected TopicManagementResponse execute() throws FirebaseMessagingException {
return messagingClient.unsubscribeFromTopic(topic, registrationTokens);
}
};
}

/**
* Unsubscribes a list of registration tokens from a topic using the legacy Instance ID API.
*
* @deprecated Use {@link #unsubscribeFromTopic(List, String)} instead.
*/
@Deprecated
public TopicManagementResponse unsubscribeFromTopicLegacy(
@NonNull List<String> registrationTokens,
@NonNull String topic) throws FirebaseMessagingException {
return unsubscribeLegacyOp(registrationTokens, topic).call();
}

/**
* Similar to {@link #unsubscribeFromTopicLegacy(List, String)} but performs the operation
* asynchronously.
*
* @deprecated Use {@link #unsubscribeFromTopicAsync(List, String)} instead.
*/
@Deprecated
public ApiFuture<TopicManagementResponse> unsubscribeFromTopicLegacyAsync(
@NonNull List<String> registrationTokens, @NonNull String topic) {
return unsubscribeLegacyOp(registrationTokens, topic).callAsync(app);
}

private CallableOperation<TopicManagementResponse, FirebaseMessagingException>
unsubscribeLegacyOp(final List<String> registrationTokens, final String topic) {
checkRegistrationTokens(registrationTokens);
checkTopic(topic);
final InstanceIdClient instanceIdClient = getInstanceIdClient();
return new CallableOperation<TopicManagementResponse, FirebaseMessagingException>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@ interface FirebaseMessagingClient {
*/
BatchResponse sendAll(List<Message> messages, boolean dryRun) throws FirebaseMessagingException;

/**
* Subscribes a list of registration tokens to a topic via the FCM v1 API.
*
* @param topic Name of the topic.
* @param registrationTokens A list of registration tokens.
* @return A {@link TopicManagementResponse}.
* @throws FirebaseMessagingException If an error occurs.
*/
TopicManagementResponse subscribeToTopic(
String topic, List<String> registrationTokens) throws FirebaseMessagingException;

/**
* Unsubscribes a list of registration tokens from a topic via the FCM v1 API.
*
* @param topic Name of the topic.
* @param registrationTokens A list of registration tokens.
* @return A {@link TopicManagementResponse}.
* @throws FirebaseMessagingException If an error occurs.
*/
TopicManagementResponse unsubscribeFromTopic(
String topic, List<String> registrationTokens) throws FirebaseMessagingException;
}
Loading
Loading