@@ -412,31 +412,10 @@ public void setUserId(String userId) {
412
412
onLogOut ();
413
413
_email = null ;
414
414
_userId = userId ;
415
- createUserForUserId ();
416
415
storeEmailAndUserId ();
417
416
onLogIn ();
418
417
}
419
418
420
- /**
421
- * Creates a user profile for a userId if it does not yet exist.
422
- */
423
- public void createUserForUserId () {
424
- if (!checkSDKInitialization () || _userId == null ) {
425
- return ;
426
- }
427
-
428
- JSONObject requestJSON = new JSONObject ();
429
- try {
430
- addEmailOrUserIdToJson (requestJSON );
431
- requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
432
-
433
- sendPostRequest (IterableConstants .ENDPOINT_CREATE_USERID , requestJSON );
434
- }
435
- catch (JSONException e ) {
436
- e .printStackTrace ();
437
- }
438
- }
439
-
440
419
/**
441
420
* Tracks a click on the uri if it is an iterable link.
442
421
* @param uri the
@@ -548,7 +527,21 @@ public void registerDeviceToken(final String applicationName, final String token
548
527
if (token != null ) {
549
528
new Thread (new Runnable () {
550
529
public void run () {
551
- registerDeviceToken (applicationName , token , IterableConstants .MESSAGING_PLATFORM_FIREBASE , null );
530
+ if (getUserId () != null ) {
531
+ createUserForUserId (new IterableHelper .SuccessHandler () {
532
+ @ Override
533
+ public void onSuccess (JSONObject data ) {
534
+ registerDeviceToken (applicationName , token , IterableConstants .MESSAGING_PLATFORM_FIREBASE , null );
535
+ }
536
+ }, new IterableHelper .FailureHandler () {
537
+ @ Override
538
+ public void onFailure (String reason , JSONObject data ) {
539
+ IterableLogger .e (TAG , "Could not create user: " + reason );
540
+ }
541
+ });
542
+ } else {
543
+ registerDeviceToken (applicationName , token , IterableConstants .MESSAGING_PLATFORM_FIREBASE , null );
544
+ }
552
545
}
553
546
}).start ();
554
547
}
@@ -1399,6 +1392,26 @@ private void handleDDL(JSONObject response) {
1399
1392
setDDLChecked (true );
1400
1393
}
1401
1394
1395
+ /**
1396
+ * Creates a user profile for a userId if it does not yet exist.
1397
+ */
1398
+ private void createUserForUserId (IterableHelper .SuccessHandler onSuccess , IterableHelper .FailureHandler onFailure ) {
1399
+ if (!checkSDKInitialization () || _userId == null ) {
1400
+ return ;
1401
+ }
1402
+
1403
+ JSONObject requestJSON = new JSONObject ();
1404
+ try {
1405
+ addEmailOrUserIdToJson (requestJSON );
1406
+ requestJSON .put (IterableConstants .KEY_USER_ID , _userId );
1407
+
1408
+ sendPostRequest (IterableConstants .ENDPOINT_CREATE_USERID , requestJSON , onSuccess , onFailure );
1409
+ }
1410
+ catch (JSONException e ) {
1411
+ e .printStackTrace ();
1412
+ }
1413
+ }
1414
+
1402
1415
//---------------------------------------------------------------------------------------
1403
1416
//endregion
1404
1417
0 commit comments