@@ -56,11 +56,17 @@ protected void scheduleSyncToServer() {
56
56
void setEmail (String email , String emailAuthHash ) {
57
57
JSONObject syncValues = getUserStateForModification ().syncValues ;
58
58
59
- if (email .equals (syncValues .optString ("identifier" )) && syncValues .optString ("email_auth_hash" ).equals (emailAuthHash == null ? "" : emailAuthHash )) {
59
+ boolean noChange = email .equals (syncValues .optString ("identifier" )) &&
60
+ syncValues .optString ("email_auth_hash" ).equals (emailAuthHash == null ? "" : emailAuthHash );
61
+ if (noChange ) {
60
62
OneSignal .fireEmailUpdateSuccess ();
61
63
return ;
62
64
}
63
65
66
+ String existingEmail = syncValues .optString ("identifier" , null );
67
+ if (existingEmail == null )
68
+ setSyncAsNewSession ();
69
+
64
70
try {
65
71
JSONObject emailJSON = new JSONObject ();
66
72
emailJSON .put ("identifier" , email );
@@ -69,7 +75,6 @@ void setEmail(String email, String emailAuthHash) {
69
75
emailJSON .put ("email_auth_hash" , emailAuthHash );
70
76
71
77
if (emailAuthHash == null ) {
72
- String existingEmail = syncValues .optString ("identifier" , null );
73
78
if (existingEmail != null && !existingEmail .equals (email )) {
74
79
OneSignal .saveEmailId ("" );
75
80
resetCurrentState ();
@@ -78,6 +83,7 @@ void setEmail(String email, String emailAuthHash) {
78
83
}
79
84
80
85
generateJsonDiff (syncValues , emailJSON , syncValues , null );
86
+ scheduleSyncToServer ();
81
87
}
82
88
catch (JSONException e ) {
83
89
e .printStackTrace ();
@@ -107,8 +113,13 @@ protected void addOnSessionOrCreateExtras(JSONObject jsonBody) {
107
113
@ Override
108
114
void logoutEmail () {
109
115
OneSignal .saveEmailId ("" );
116
+
110
117
resetCurrentState ();
111
- nextSyncIsSession = false ;
118
+ toSyncUserState .syncValues .remove ("identifier" );
119
+ toSyncUserState .syncValues .remove ("email_auth_hash" );
120
+ toSyncUserState .syncValues .remove ("device_player_id" );
121
+ toSyncUserState .persistState ();
122
+
112
123
OneSignal .getPermissionSubscriptionState ().emailSubscriptionStatus .clearEmailAndId ();
113
124
}
114
125
0 commit comments