aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging/FIRMessagingPendingTopicsList.m
diff options
context:
space:
mode:
authorGravatar Chen Liang <chliang@google.com>2018-03-30 11:41:38 -0700
committerGravatar GitHub <noreply@github.com>2018-03-30 11:41:38 -0700
commit653aea7b50247bb0f6a7e8e1b4ab782553849f74 (patch)
tree0e2b9d8d660aee63a9a4659203e5ca9c1b692c61 /Firebase/Messaging/FIRMessagingPendingTopicsList.m
parentcdd855423a79ed0191b37b7dcac2df9fb342c9a5 (diff)
Adding a new topic subscription/unsubcription with completion handler method (#1001)
* add new topic subscription/unsubscription method with handler
Diffstat (limited to 'Firebase/Messaging/FIRMessagingPendingTopicsList.m')
-rw-r--r--Firebase/Messaging/FIRMessagingPendingTopicsList.m83
1 files changed, 43 insertions, 40 deletions
diff --git a/Firebase/Messaging/FIRMessagingPendingTopicsList.m b/Firebase/Messaging/FIRMessagingPendingTopicsList.m
index 8bab770..b10b552 100644
--- a/Firebase/Messaging/FIRMessagingPendingTopicsList.m
+++ b/Firebase/Messaging/FIRMessagingPendingTopicsList.m
@@ -217,46 +217,49 @@ NSString *const kPendingTopicsTimestampEncodingKey = @"ts";
[self.topicsInFlight addObject:topic];
}
FIRMessaging_WEAKIFY(self);
- [self.delegate pendingTopicsList:self
- requestedUpdateForTopic:topic
- action:self.currentBatch.action
- completion:^(FIRMessagingTopicOperationResult result, NSError * error) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- FIRMessaging_STRONGIFY(self);
- @synchronized (self) {
- [self.topicsInFlight removeObject:topic];
-
- BOOL recoverableError = [self subscriptionErrorIsRecoverable:error];
- if (result == FIRMessagingTopicOperationResultSucceeded ||
- result == FIRMessagingTopicOperationResultCancelled ||
- !recoverableError) {
- // Notify our handlers and remove the topic from our batch
- NSMutableArray *handlers = self.currentBatch.topicHandlers[topic];
- if (handlers.count) {
- dispatch_async(dispatch_get_main_queue(), ^{
- for (FIRMessagingTopicOperationCompletion handler in handlers) {
- handler(result, error);
- }
- [handlers removeAllObjects];
- });
- }
- [self.currentBatch.topics removeObject:topic];
- [self.currentBatch.topicHandlers removeObjectForKey:topic];
- if (self.currentBatch.topics.count == 0) {
- // All topic updates successfully finished in this batch, move on to the next batch
- [self.topicBatches removeObject:self.currentBatch];
- self.currentBatch = nil;
- }
- [self.delegate pendingTopicsListDidUpdate:self];
- FIRMessaging_WEAKIFY(self)
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- FIRMessaging_STRONGIFY(self)
- [self resumeOperationsIfNeeded];
- });
- }
- }
- });
- }];
+ [self.delegate
+ pendingTopicsList:self
+ requestedUpdateForTopic:topic
+ action:self.currentBatch.action
+ completion:^(NSError *error) {
+ dispatch_async(
+ dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
+ FIRMessaging_STRONGIFY(self);
+ @synchronized(self) {
+ [self.topicsInFlight removeObject:topic];
+
+ BOOL recoverableError = [self subscriptionErrorIsRecoverable:error];
+ if (!error || !recoverableError) {
+ // Notify our handlers and remove the topic from our batch
+ NSMutableArray *handlers = self.currentBatch.topicHandlers[topic];
+ if (handlers.count) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ for (FIRMessagingTopicOperationCompletion handler in handlers) {
+ handler(error);
+ }
+ [handlers removeAllObjects];
+ });
+ }
+ [self.currentBatch.topics removeObject:topic];
+ [self.currentBatch.topicHandlers removeObjectForKey:topic];
+ if (self.currentBatch.topics.count == 0) {
+ // All topic updates successfully finished in this batch, move on
+ // to the next batch
+ [self.topicBatches removeObject:self.currentBatch];
+ self.currentBatch = nil;
+ }
+ [self.delegate pendingTopicsListDidUpdate:self];
+ FIRMessaging_WEAKIFY(self);
+ dispatch_async(
+ dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
+ ^{
+ FIRMessaging_STRONGIFY(self);
+ [self resumeOperationsIfNeeded];
+ });
+ }
+ }
+ });
+ }];
}
@end