This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-17
lines changed Expand file tree Collapse file tree 2 files changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -139,9 +139,13 @@ export function subscribeToTopic(topicName) {
139139 return ;
140140 }
141141
142- // TODO since Cloud Messaging 17.0.0 this returns a Task instead of void (so we can resolve onSuccess)
143- com . google . firebase . messaging . FirebaseMessaging . getInstance ( ) . subscribeToTopic ( topicName ) ;
144- resolve ( ) ;
142+ const onCompleteListener = new com . google . android . gms . tasks . OnCompleteListener ( {
143+ onComplete : task => task . isSuccessful ( ) ? resolve ( ) : reject ( task . getException ( ) && task . getException ( ) . getReason ? task . getException ( ) . getReason ( ) : task . getException ( ) )
144+ } ) ;
145+
146+ com . google . firebase . messaging . FirebaseMessaging . getInstance ( )
147+ . subscribeToTopic ( topicName )
148+ . addOnCompleteListener ( onCompleteListener ) ;
145149 } catch ( ex ) {
146150 console . log ( "Error in firebase.subscribeToTopic: " + ex ) ;
147151 reject ( ex ) ;
@@ -158,8 +162,13 @@ export function unsubscribeFromTopic(topicName) {
158162 return ;
159163 }
160164
161- com . google . firebase . messaging . FirebaseMessaging . getInstance ( ) . unsubscribeFromTopic ( topicName ) ;
162- resolve ( ) ;
165+ const onCompleteListener = new com . google . android . gms . tasks . OnCompleteListener ( {
166+ onComplete : task => task . isSuccessful ( ) ? resolve ( ) : reject ( task . getException ( ) && task . getException ( ) . getReason ? task . getException ( ) . getReason ( ) : task . getException ( ) )
167+ } ) ;
168+
169+ com . google . firebase . messaging . FirebaseMessaging . getInstance ( )
170+ . unsubscribeFromTopic ( topicName )
171+ . addOnCompleteListener ( onCompleteListener ) ;
163172 } catch ( ex ) {
164173 console . log ( "Error in firebase.unsubscribeFromTopic: " + ex ) ;
165174 reject ( ex ) ;
Original file line number Diff line number Diff line change @@ -216,13 +216,9 @@ export function subscribeToTopic(topicName) {
216216 return ;
217217 }
218218
219- if ( topicName . indexOf ( "/topics/" ) === - 1 ) {
220- topicName = "/topics/" + topicName ;
221- }
222-
223- // TODO there's also (un)subscribeToTopicCompletion (resolve when completed).. perhaps this has been added to Android as well
224- FIRMessaging . messaging ( ) . subscribeToTopic ( topicName ) ;
225- resolve ( ) ;
219+ FIRMessaging . messaging ( ) . subscribeToTopicCompletion ( topicName , ( error : NSError ) => {
220+ error ? reject ( error . localizedDescription ) : resolve ( ) ;
221+ } ) ;
226222 } catch ( ex ) {
227223 console . log ( "Error in firebase.subscribeToTopic: " + ex ) ;
228224 reject ( ex ) ;
@@ -239,11 +235,9 @@ export function unsubscribeFromTopic(topicName) {
239235 return ;
240236 }
241237
242- if ( topicName . indexOf ( "/topics/" ) === - 1 ) {
243- topicName = "/topics/" + topicName ;
244- }
245- FIRMessaging . messaging ( ) . unsubscribeFromTopic ( topicName ) ;
246- resolve ( ) ;
238+ FIRMessaging . messaging ( ) . unsubscribeFromTopicCompletion ( topicName , error => {
239+ error ? reject ( error . localizedDescription ) : resolve ( ) ;
240+ } ) ;
247241 } catch ( ex ) {
248242 console . log ( "Error in firebase.unsubscribeFromTopic: " + ex ) ;
249243 reject ( ex ) ;
You can’t perform that action at this time.
0 commit comments