Look for a pushed_at value in server message batches

pull/14/head
Sam Bosley 13 years ago
parent d3488416d0
commit f9232b7bf4

@ -1,6 +1,7 @@
package com.todoroo.astrid.actfm.sync;
import java.io.IOException;
import java.text.ParseException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -14,6 +15,7 @@ import android.util.Log;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.actfm.sync.messages.BriefMe;
import com.todoroo.astrid.actfm.sync.messages.ClientToServerMessage;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
@ -166,11 +168,18 @@ public class ActFmSyncThread {
JSONObject response = actFmInvoker.postSync(payload, token);
// process responses
JSONArray serverMessagesJson = response.optJSONArray("messages");
String modelPushedAtString = response.optString("pushed_at");
long modelPushedAt = 0;
try {
modelPushedAt = DateUtilities.parseIso8601(modelPushedAtString);
} catch (ParseException e) {
// Unparseable date
}
if (serverMessagesJson != null) {
for (int i = 0; i < serverMessagesJson.length(); i++) {
JSONObject serverMessageJson = serverMessagesJson.optJSONObject(i);
if (serverMessageJson != null) {
ServerToClientMessage serverMessage = ServerToClientMessage.instantiateMessage(serverMessageJson);
ServerToClientMessage serverMessage = ServerToClientMessage.instantiateMessage(serverMessageJson, modelPushedAt);
if (serverMessage != null) {
serverMessage.processMessage();
} else {

@ -8,6 +8,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.RemoteModelDao;
@ -21,11 +22,13 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
private final RemoteModelDao<TYPE> dao;
private final String table;
private final long pushedAt;
public MakeChanges(JSONObject json, RemoteModelDao<TYPE> dao) {
public MakeChanges(JSONObject json, RemoteModelDao<TYPE> dao, long pushedAt) {
super(json);
table = json.optString("table");
this.table = json.optString("table");
this.dao = dao;
this.pushedAt = pushedAt;
}
@Override
@ -47,6 +50,9 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
}
nonColumnChanges(changes, model);
LongProperty pushedAtProperty = (LongProperty) NameMaps.serverColumnNameToLocalProperty(table, "pushed_at");
if (pushedAtProperty != null && pushedAt > 0)
model.setValue(pushedAtProperty, pushedAt);
StringProperty uuidProperty = (StringProperty) NameMaps.serverColumnNameToLocalProperty(table, "uuid");
if (!model.getSetValues().containsKey(uuidProperty.name))

@ -24,10 +24,10 @@ public abstract class ServerToClientMessage {
this.json = json;
}
public static ServerToClientMessage instantiateMessage(JSONObject json) {
public static ServerToClientMessage instantiateMessage(JSONObject json, long pushedAt) {
String type = json.optString("type");
if (TYPE_MAKE_CHANGES.equals(type))
return instantiateMakeChanges(json);
return instantiateMakeChanges(json, pushedAt);
else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type))
return new AcknowledgeChange(json);
else if (TYPE_USER_DATA.equals(type))
@ -40,14 +40,14 @@ public abstract class ServerToClientMessage {
return null;
}
private static MakeChanges<?> instantiateMakeChanges(JSONObject json) {
private static MakeChanges<?> instantiateMakeChanges(JSONObject json, long pushedAt) {
String table = json.optString("table");
if (NameMaps.TABLE_ID_TASKS.equals(table))
return new MakeChanges<Task>(json, PluginServices.getTaskDao());
return new MakeChanges<Task>(json, PluginServices.getTaskDao(), pushedAt);
else if (NameMaps.TABLE_ID_TAGS.equals(table))
return new MakeChanges<TagData>(json, PluginServices.getTagDataDao());
return new MakeChanges<TagData>(json, PluginServices.getTagDataDao(), pushedAt);
else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table))
return new MakeChanges<RemoteModel>(json, null);
return new MakeChanges<RemoteModel>(json, null, 0);
else
return null;
}

Loading…
Cancel
Save