@@ -724,6 +724,11 @@ static void InstallationsGetToken() {
724
724
725
725
result.OnCompletion (
726
726
[](const Future<std::string>& result, void * voidptr) {
727
+ if (g_registration_token_mutex) {
728
+ MutexLock lock (*g_registration_token_mutex);
729
+ g_registration_token_received = true ;
730
+ HandlePendingSubscriptions ();
731
+ }
727
732
NotifyListenerOnTokenReceived (result.result ()->c_str ());
728
733
},
729
734
nullptr );
@@ -868,6 +873,9 @@ static const char kErrorMessageNoRegistrationToken[] =
868
873
" Cannot update subscription when SetTokenRegistrationOnInitEnabled is set "
869
874
" to false." ;
870
875
876
+ static const char kErrorMessageSubscriptionUnknown [] =
877
+ " Cannot update subscription for unknown reason." ;
878
+
871
879
Future<void > Subscribe (const char * topic) {
872
880
FIREBASE_ASSERT_MESSAGE_RETURN (Future<void >(), internal::IsInitialized (),
873
881
kMessagingNotInitializedError );
@@ -882,6 +890,11 @@ Future<void> Subscribe(const char* topic) {
882
890
kErrorMessageNoRegistrationToken );
883
891
} else if (g_pending_subscriptions) {
884
892
g_pending_subscriptions->push_back (PendingTopic (topic, handle));
893
+ } else {
894
+ // This shouldn't happen, since g_pending_subscriptions should be valid if
895
+ // here, but handle it to prevent abandoning the Future in case something
896
+ // happens.
897
+ api->Complete (handle, kErrorUnknown , kErrorMessageSubscriptionUnknown );
885
898
}
886
899
return MakeFuture (api, handle);
887
900
}
@@ -907,6 +920,11 @@ Future<void> Unsubscribe(const char* topic) {
907
920
kErrorMessageNoRegistrationToken );
908
921
} else if (g_pending_unsubscriptions) {
909
922
g_pending_unsubscriptions->push_back (PendingTopic (topic, handle));
923
+ } else {
924
+ // This shouldn't happen, since g_pending_unsubscriptions should be valid if
925
+ // here, but handle it to prevent abandoning the Future in case something
926
+ // happens.
927
+ api->Complete (handle, kErrorUnknown , kErrorMessageSubscriptionUnknown );
910
928
}
911
929
return MakeFuture (api, handle);
912
930
}
0 commit comments