Skip to content

Commit 330edc8

Browse files
committed
Implemented UserMigrated message, update all reference to local user id to be a string
1 parent fb8905f commit 330edc8

File tree

6 files changed

+42
-23
lines changed

6 files changed

+42
-23
lines changed

astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,9 @@ public void run() {
584584
StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider);
585585
}
586586
// Successful login, create outstanding entries
587-
long lastId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
587+
String lastId = ActFmPreferenceService.userId(); //Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
588588

589-
if (!TextUtils.isEmpty(token) && lastId == 0) {
589+
if (!TextUtils.isEmpty(token) && RemoteModel.isUuidEmpty(lastId)) {
590590
constructOutstandingTables();
591591
}
592592
runOnUiThread(new Runnable() {
@@ -620,11 +620,11 @@ private void constructOutstandingTables() {
620620

621621
@SuppressWarnings("nls")
622622
private void postAuthenticate(final JSONObject result, final String token) {
623-
long lastLoggedInUser = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
623+
String lastLoggedInUser = ActFmPreferenceService.userId();
624624

625-
if (lastLoggedInUser > 0) {
626-
long newUserId = result.optLong("id");
627-
if (lastLoggedInUser != newUserId) {
625+
if (RemoteModel.isValidUuid(lastLoggedInUser)) {
626+
String newUserId = Long.toString(result.optLong("id"));
627+
if (!lastLoggedInUser.equals(newUserId)) {
628628
// In this case, we need to either make all data private or clear all data
629629
// Prompt for choice
630630
DialogUtilities.okCancelCustomDialog(this,
@@ -831,8 +831,8 @@ private <T extends RemoteModel> void mapUuids(RemoteModelDao<T> dao, HashMap<Str
831831
private void finishSignIn(JSONObject result, String token, boolean restart) {
832832
actFmPreferenceService.setToken(token);
833833

834-
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
835-
result.optLong("id"));
834+
Preferences.setString(ActFmPreferenceService.PREF_USER_ID,
835+
Long.toString(result.optLong("id")));
836836
Preferences.setString(ActFmPreferenceService.PREF_NAME,
837837
result.optString("name"));
838838
Preferences.setString(ActFmPreferenceService.PREF_FIRST_NAME,

astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmPreferenceService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.todoroo.andlib.utility.Preferences;
1515
import com.todoroo.astrid.billing.BillingConstants;
1616
import com.todoroo.astrid.dao.RemoteModelDao;
17+
import com.todoroo.astrid.data.RemoteModel;
1718
import com.todoroo.astrid.service.StatisticsConstants;
1819
import com.todoroo.astrid.service.StatisticsService;
1920
import com.todoroo.astrid.sync.SyncProviderUtilities;
@@ -68,7 +69,7 @@ public void setToken(String setting) {
6869
* @return true if the user is now or has ever been logged in
6970
*/
7071
public boolean wasLoggedIn() {
71-
return Preferences.getLong(PREF_USER_ID, 0) > 0;
72+
return RemoteModel.isValidUuid(userId());
7273
}
7374

7475
/**

astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.todoroo.andlib.service.ContextManager;
2020
import com.todoroo.andlib.utility.DialogUtilities;
2121
import com.todoroo.andlib.utility.Preferences;
22-
import com.todoroo.astrid.actfm.sync.messages.ConvertSelfUserIdsToZero;
2322
import com.todoroo.astrid.billing.BillingConstants;
2423
import com.todoroo.astrid.dao.Database;
2524
import com.todoroo.astrid.dao.RemoteModelDao;
@@ -122,16 +121,8 @@ public void updateUserStatus() {
122121

123122
try {
124123
JSONObject status = actFmSyncService.invoke("user_status"); //$NON-NLS-1$
125-
long oldId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, -1);
126-
if (status.has("id")) {
127-
long newId = status.optLong("id");
128-
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID, newId);
129-
if (oldId > 0 && oldId != newId) {
130-
// Migrate all db userIds that = newId to 0
131-
new ConvertSelfUserIdsToZero().execute();
132-
ActFmSyncThread.clearTablePushedAtValues();
133-
}
134-
}
124+
if (status.has("id"))
125+
Preferences.setString(ActFmPreferenceService.PREF_USER_ID, Long.toString(status.optLong("id")));
135126
if (status.has("name"))
136127
Preferences.setString(ActFmPreferenceService.PREF_NAME, status.optString("name"));
137128
if (status.has("first_name"))

astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public abstract class ServerToClientMessage {
2121
public static final String TYPE_ACKNOWLEDGE_CHANGE = "AcknowledgeChange";
2222
public static final String TYPE_USER_DATA = "UserData";
2323
public static final String TYPE_DOUBLE_CHECK = "DoubleCheck";
24+
public static final String TYPE_USER_MIGRATED = "UserMigrated";
2425
public static final String TYPE_DEBUG = "Debug";
2526

2627
protected final JSONObject json;
@@ -39,8 +40,10 @@ else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type))
3940
return new AcknowledgeChange(json);
4041
else if (TYPE_USER_DATA.equals(type))
4142
return new UserData(json);
42-
else if (TYPE_DOUBLE_CHECK.equals(json))
43+
else if (TYPE_DOUBLE_CHECK.equals(type))
4344
return new DoubleCheck(json);
45+
else if (TYPE_USER_MIGRATED.equals(type))
46+
return new UserMigrated(json);
4447
else if (TYPE_DEBUG.equals(type))
4548
return new Debug(json);
4649

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.todoroo.astrid.actfm.sync.messages;
2+
3+
import org.json.JSONObject;
4+
5+
import com.todoroo.andlib.utility.Preferences;
6+
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
7+
import com.todoroo.astrid.data.RemoteModel;
8+
9+
public class UserMigrated extends ServerToClientMessage {
10+
11+
public UserMigrated(JSONObject json) {
12+
super(json);
13+
}
14+
15+
@Override
16+
public void processMessage(String serverTime) {
17+
String newUuid = json.optString("new_user_id"); //$NON-NLS-1$
18+
if (RemoteModel.isValidUuid(newUuid)) {
19+
Preferences.setString(ActFmPreferenceService.PREF_USER_ID, newUuid);
20+
new ConvertSelfUserIdsToZero();
21+
}
22+
}
23+
24+
}

tests-sync/src/com/todoroo/astrid/sync/repeats/RepeatTestsActFmSync.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private void authenticate(String email, String firstName, String lastName, Strin
8585
private void postAuthenticate(JSONObject result, String token) {
8686
actFmPreferenceService.setToken(token);
8787

88-
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
89-
result.optLong("id"));
88+
Preferences.setString(ActFmPreferenceService.PREF_USER_ID,
89+
Long.toString(result.optLong("id")));
9090
Preferences.setString(ActFmPreferenceService.PREF_NAME, result.optString("name"));
9191
Preferences.setString(ActFmPreferenceService.PREF_EMAIL, result.optString("email"));
9292
Preferences.setString(ActFmPreferenceService.PREF_PICTURE, result.optString("picture"));

0 commit comments

Comments
 (0)