Implemented UserMigrated message, update all reference to local user id to be a string

pull/14/head
Sam Bosley 13 years ago
parent fb8905f469
commit 330edc80b0

@ -584,9 +584,9 @@ public class ActFmLoginActivity extends SherlockFragmentActivity {
StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider);
}
// Successful login, create outstanding entries
long lastId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
String lastId = ActFmPreferenceService.userId(); //Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
if (!TextUtils.isEmpty(token) && lastId == 0) {
if (!TextUtils.isEmpty(token) && RemoteModel.isUuidEmpty(lastId)) {
constructOutstandingTables();
}
runOnUiThread(new Runnable() {
@ -620,11 +620,11 @@ public class ActFmLoginActivity extends SherlockFragmentActivity {
@SuppressWarnings("nls")
private void postAuthenticate(final JSONObject result, final String token) {
long lastLoggedInUser = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, 0);
String lastLoggedInUser = ActFmPreferenceService.userId();
if (lastLoggedInUser > 0) {
long newUserId = result.optLong("id");
if (lastLoggedInUser != newUserId) {
if (RemoteModel.isValidUuid(lastLoggedInUser)) {
String newUserId = Long.toString(result.optLong("id"));
if (!lastLoggedInUser.equals(newUserId)) {
// In this case, we need to either make all data private or clear all data
// Prompt for choice
DialogUtilities.okCancelCustomDialog(this,
@ -831,8 +831,8 @@ public class ActFmLoginActivity extends SherlockFragmentActivity {
private void finishSignIn(JSONObject result, String token, boolean restart) {
actFmPreferenceService.setToken(token);
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
result.optLong("id"));
Preferences.setString(ActFmPreferenceService.PREF_USER_ID,
Long.toString(result.optLong("id")));
Preferences.setString(ActFmPreferenceService.PREF_NAME,
result.optString("name"));
Preferences.setString(ActFmPreferenceService.PREF_FIRST_NAME,

@ -14,6 +14,7 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.dao.RemoteModelDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.sync.SyncProviderUtilities;
@ -68,7 +69,7 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
* @return true if the user is now or has ever been logged in
*/
public boolean wasLoggedIn() {
return Preferences.getLong(PREF_USER_ID, 0) > 0;
return RemoteModel.isValidUuid(userId());
}
/**

@ -19,7 +19,6 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.messages.ConvertSelfUserIdsToZero;
import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.RemoteModelDao;
@ -122,16 +121,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
try {
JSONObject status = actFmSyncService.invoke("user_status"); //$NON-NLS-1$
long oldId = Preferences.getLong(ActFmPreferenceService.PREF_USER_ID, -1);
if (status.has("id")) {
long newId = status.optLong("id");
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID, newId);
if (oldId > 0 && oldId != newId) {
// Migrate all db userIds that = newId to 0
new ConvertSelfUserIdsToZero().execute();
ActFmSyncThread.clearTablePushedAtValues();
}
}
if (status.has("id"))
Preferences.setString(ActFmPreferenceService.PREF_USER_ID, Long.toString(status.optLong("id")));
if (status.has("name"))
Preferences.setString(ActFmPreferenceService.PREF_NAME, status.optString("name"));
if (status.has("first_name"))

@ -21,6 +21,7 @@ public abstract class ServerToClientMessage {
public static final String TYPE_ACKNOWLEDGE_CHANGE = "AcknowledgeChange";
public static final String TYPE_USER_DATA = "UserData";
public static final String TYPE_DOUBLE_CHECK = "DoubleCheck";
public static final String TYPE_USER_MIGRATED = "UserMigrated";
public static final String TYPE_DEBUG = "Debug";
protected final JSONObject json;
@ -39,8 +40,10 @@ public abstract class ServerToClientMessage {
return new AcknowledgeChange(json);
else if (TYPE_USER_DATA.equals(type))
return new UserData(json);
else if (TYPE_DOUBLE_CHECK.equals(json))
else if (TYPE_DOUBLE_CHECK.equals(type))
return new DoubleCheck(json);
else if (TYPE_USER_MIGRATED.equals(type))
return new UserMigrated(json);
else if (TYPE_DEBUG.equals(type))
return new Debug(json);

@ -0,0 +1,24 @@
package com.todoroo.astrid.actfm.sync.messages;
import org.json.JSONObject;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.data.RemoteModel;
public class UserMigrated extends ServerToClientMessage {
public UserMigrated(JSONObject json) {
super(json);
}
@Override
public void processMessage(String serverTime) {
String newUuid = json.optString("new_user_id"); //$NON-NLS-1$
if (RemoteModel.isValidUuid(newUuid)) {
Preferences.setString(ActFmPreferenceService.PREF_USER_ID, newUuid);
new ConvertSelfUserIdsToZero();
}
}
}

@ -85,8 +85,8 @@ public class RepeatTestsActFmSync extends AbstractSyncRepeatTests<Task> {
private void postAuthenticate(JSONObject result, String token) {
actFmPreferenceService.setToken(token);
Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
result.optLong("id"));
Preferences.setString(ActFmPreferenceService.PREF_USER_ID,
Long.toString(result.optLong("id")));
Preferences.setString(ActFmPreferenceService.PREF_NAME, result.optString("name"));
Preferences.setString(ActFmPreferenceService.PREF_EMAIL, result.optString("email"));
Preferences.setString(ActFmPreferenceService.PREF_PICTURE, result.optString("picture"));

Loading…
Cancel
Save