Deprecated the user json properties, clear some of them on sync

pull/14/head
Sam Bosley 12 years ago
parent b1ae98aec4
commit 51bf8445e6

@ -35,7 +35,7 @@ abstract public class RemoteModel extends AbstractModel {
protected static final String USER_JSON_PROPERTY_NAME = "user"; //$NON-NLS-1$
/** user json property */
public static final StringProperty USER_JSON_PROPERTY = new StringProperty(null, USER_JSON_PROPERTY_NAME);
@Deprecated public static final StringProperty USER_JSON_PROPERTY = new StringProperty(null, USER_JSON_PROPERTY_NAME);
/** pushed at date property name */
public static final String PUSHED_AT_PROPERTY_NAME = "pushedAt"; //$NON-NLS-1$

@ -50,7 +50,7 @@ public final class TagData extends RemoteModel {
TABLE, USER_ID_PROPERTY_NAME, Property.PROP_FLAG_USER_ID);
/** User Object (JSON) */
public static final StringProperty USER = new StringProperty(
@Deprecated public static final StringProperty USER = new StringProperty(
TABLE, USER_JSON_PROPERTY_NAME);
/** Remote goal id */

@ -162,11 +162,11 @@ public final class Task extends RemoteModel {
TABLE, USER_ID_PROPERTY_NAME, Property.PROP_FLAG_USER_ID);
/** User Object (JSON) */
public static final StringProperty USER = new StringProperty(
@Deprecated public static final StringProperty USER = new StringProperty(
TABLE, USER_JSON_PROPERTY_NAME);
/** Creator user id */
public static final LongProperty CREATOR_ID = new LongProperty(
public static final StringProperty CREATOR_ID = new StringProperty(
TABLE, "creatorId", Property.PROP_FLAG_USER_ID);
/** Last Sync date */

@ -71,7 +71,7 @@ public class Update extends RemoteModel {
TABLE, USER_ID_PROPERTY_NAME);
/** From User Object (JSON) */
public static final StringProperty USER = new StringProperty(
@Deprecated public static final StringProperty USER = new StringProperty(
TABLE, USER_JSON_PROPERTY_NAME);
/** Other user id */

@ -8,13 +8,11 @@ package com.todoroo.astrid.actfm.sync;
import org.json.JSONException;
import org.json.JSONObject;
import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.sync.SyncProviderUtilities;
@ -59,8 +57,12 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
/**
* @return get user id
*/
public static long userId() {
return Preferences.getLong(PREF_USER_ID, -2L);
public static String userId() {
try {
return Preferences.getStringValue(PREF_USER_ID);
} catch (Exception e) {
return Long.toString(Preferences.getLong(PREF_USER_ID, -2L));
}
}
/** Act.fm current user id */
@ -103,9 +105,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
* @return
*/
public static JSONObject userFromModel(RemoteModel model) {
if(model.getValue(RemoteModel.USER_ID_PROPERTY) == 0) {
if (Task.USER_ID_SELF.equals(model.getValue(RemoteModel.USER_ID_PROPERTY))) {
return thisUser();
}else {
} else {
try {
return new JSONObject(model.getValue(RemoteModel.USER_JSON_PROPERTY));
} catch (JSONException e) {
@ -114,20 +116,6 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
}
}
@SuppressWarnings("nls")
public static String updateToString(Update update) {
JSONObject updateUser = ActFmPreferenceService.userFromModel(update);
String description = update.getValue(Update.ACTION);
String message = update.getValue(Update.MESSAGE);
if(update.getValue(Update.ACTION_CODE).equals("task_comment") ||
update.getValue(Update.ACTION_CODE).equals("tag_comment"))
description = message;
else if(!TextUtils.isEmpty(message))
description += " " + message;
return String.format("%s: %s", updateUser.optString("name"), description);
}
public synchronized static JSONObject thisUser() {
if(user == null) {
user = new JSONObject();
@ -151,7 +139,7 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
user.put("premium", isPremiumUser());
user.put("email", Preferences.getStringValue(PREF_EMAIL));
user.put("picture", Preferences.getStringValue(PREF_PICTURE));
user.put("id", Preferences.getLong(PREF_USER_ID, 0));
user.put("id", ActFmPreferenceService.userId());
} catch (JSONException e) {
throw new RuntimeException(e);
}

@ -54,9 +54,7 @@ public class JSONChangeToPropertyVisitor implements PropertyVisitor<Void, String
public Void visitLong(Property<Long> property, String key) {
try {
long value = data.optLong(key, 0);
if (property.checkFlag(Property.PROP_FLAG_USER_ID) && value == ActFmPreferenceService.userId())
value = 0;
else if (property.checkFlag(Property.PROP_FLAG_DATE)) {
if (property.checkFlag(Property.PROP_FLAG_DATE)) {
String valueString = data.getString(key);
try {
value = DateUtilities.parseIso8601(valueString);
@ -91,6 +89,11 @@ public class JSONChangeToPropertyVisitor implements PropertyVisitor<Void, String
String value = data.getString(key);
if ("null".equals(value))
value = "";
else if (property.checkFlag(Property.PROP_FLAG_USER_ID) && ActFmPreferenceService.userId().equals(value))
value = Task.USER_ID_SELF;
if (property.equals(Task.USER_ID))
model.setValue(Task.USER, "{}"); // Clear this value for migration purposes
model.setValue((StringProperty) property, value);
} catch (JSONException e) {
try {

@ -23,6 +23,7 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.MetadataApiDao.MetadataCriteria;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.tags.TagMetadata;
import com.todoroo.astrid.tags.TagService;
@ -223,6 +224,11 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
TagMetadata.TAG_UUID.eq(uuid)), template);
}
if (changes.has("member_added")) {
model.setValue(TagData.MEMBERS, "{}"); // Clear this value for migration purposes
//TODO: Do more things here also
}
}
}

Loading…
Cancel
Save