Set general pushed at value in makechanges

pull/14/head
Sam Bosley 12 years ago
parent 11f86e32e8
commit bba063739f

@ -313,6 +313,7 @@ public class ActFmSyncThread {
try {
JSONObject response = actFmInvoker.postSync(payload, entity, token);
// process responses
String time = response.optString("time");
JSONArray serverMessagesJson = response.optJSONArray("messages");
if (serverMessagesJson != null) {
for (int i = 0; i < serverMessagesJson.length(); i++) {
@ -321,7 +322,7 @@ public class ActFmSyncThread {
ServerToClientMessage serverMessage = ServerToClientMessage.instantiateMessage(serverMessageJson);
if (serverMessage != null) {
syncLog("Processing server message of type " + serverMessage.getClass().getSimpleName());
serverMessage.processMessage();
serverMessage.processMessage(time);
} else {
syncLog("Unable to instantiate message " + serverMessageJson.toString());
}

@ -36,7 +36,7 @@ public class AcknowledgeChange extends ServerToClientMessage {
}
@Override
public void processMessage() {
public void processMessage(String serverTime) {
JSONArray idsArray = json.optJSONArray("ids"); //$NON-NLS-1$
if (idsArray != null && dao != null) {
ArrayList<Long> idsList = new ArrayList<Long>();

@ -13,7 +13,7 @@ public class Debug extends ServerToClientMessage {
@Override
@SuppressWarnings("nls")
public void processMessage() {
public void processMessage(String serverTime) {
String message = json.optString("message");
if (!TextUtils.isEmpty(message))
Log.w("actfm-debug-message", message);

@ -9,7 +9,7 @@ public class DoubleCheck extends ServerToClientMessage {
}
@Override
public void processMessage() {
public void processMessage(String serverTime) {
// TODO Auto-generated method stub
}

@ -1,5 +1,6 @@
package com.todoroo.astrid.actfm.sync.messages;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
@ -65,7 +66,7 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
return model;
}
private static <T extends RemoteModel> void saveOrUpdateModelAfterChanges(RemoteModelDao<T> dao, T model, String oldUuid, String uuid, Criterion orCriterion) {
private static <T extends RemoteModel> void saveOrUpdateModelAfterChanges(RemoteModelDao<T> dao, T model, String oldUuid, String uuid, String serverTime, Criterion orCriterion) {
Criterion uuidCriterion;
if (oldUuid == null)
uuidCriterion = RemoteModel.UUID_PROPERTY.eq(uuid);
@ -76,6 +77,16 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
uuidCriterion = Criterion.or(uuidCriterion, orCriterion);
if (model.getSetValues() != null && model.getSetValues().size() > 0) {
long pushedAt;
try {
pushedAt = DateUtilities.parseIso8601(serverTime);
} catch (ParseException e) {
pushedAt = 0;
}
if (pushedAt > 0)
model.setValue(RemoteModel.PUSHED_AT_PROPERTY, pushedAt);
model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
if (dao.update(uuidCriterion, model) <= 0) { // If update doesn't update rows. create a new model
model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
@ -85,7 +96,7 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
}
@Override
public void processMessage() {
public void processMessage(String serverTime) {
JSONObject changes = json.optJSONObject("changes");
String uuid = json.optString("uuid");
if (changes != null && !TextUtils.isEmpty(uuid)) {
@ -105,7 +116,7 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
if (model.getSetValues() != null && !model.getSetValues().containsKey(uuidProperty.name))
model.setValue(uuidProperty, uuid);
saveOrUpdateModelAfterChanges(dao, model, oldUuid, uuid, getMatchCriterion(model));
saveOrUpdateModelAfterChanges(dao, model, oldUuid, uuid, serverTime, getMatchCriterion(model));
afterSaveChanges(changes, model, uuid, oldUuid);
} catch (IllegalAccessException e) {

@ -42,7 +42,7 @@ public class NowBriefed<TYPE extends RemoteModel> extends ServerToClientMessage
}
@Override
public void processMessage() {
public void processMessage(String serverTime) {
if (pushedAt > 0) {
if (TextUtils.isEmpty(uuid)) {
if (!TextUtils.isEmpty(taskId)) {

@ -13,7 +13,7 @@ import com.todoroo.astrid.data.UserActivity;
@SuppressWarnings("nls")
public abstract class ServerToClientMessage {
public abstract void processMessage();
public abstract void processMessage(String serverTime);
public static final String TYPE_MAKE_CHANGES = "MakeChanges";
public static final String TYPE_NOW_BRIEFED = "NowBriefed";

@ -20,7 +20,7 @@ public class UserData extends ServerToClientMessage {
@Override
@SuppressWarnings("nls")
public void processMessage() {
public void processMessage(String serverTime) {
String uuid = json.optString("uuid");
String email = json.optString("email");

Loading…
Cancel
Save