From bba063739f05e7d6f97b76f870db77e84910aaeb Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 7 Mar 2013 11:49:50 -0800 Subject: [PATCH] Set general pushed at value in makechanges --- .../astrid/actfm/sync/ActFmSyncThread.java | 3 ++- .../actfm/sync/messages/AcknowledgeChange.java | 2 +- .../astrid/actfm/sync/messages/Debug.java | 2 +- .../astrid/actfm/sync/messages/DoubleCheck.java | 2 +- .../astrid/actfm/sync/messages/MakeChanges.java | 17 ++++++++++++++--- .../astrid/actfm/sync/messages/NowBriefed.java | 2 +- .../sync/messages/ServerToClientMessage.java | 2 +- .../astrid/actfm/sync/messages/UserData.java | 2 +- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java index b35901526..071deb987 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -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()); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/AcknowledgeChange.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/AcknowledgeChange.java index b24a28f2d..49d3d2716 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/AcknowledgeChange.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/AcknowledgeChange.java @@ -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 idsList = new ArrayList(); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/Debug.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/Debug.java index bb8e20c00..f8bbc667f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/Debug.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/Debug.java @@ -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); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/DoubleCheck.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/DoubleCheck.java index e5b0d7fdf..345c4a88e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/DoubleCheck.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/DoubleCheck.java @@ -9,7 +9,7 @@ public class DoubleCheck extends ServerToClientMessage { } @Override - public void processMessage() { + public void processMessage(String serverTime) { // TODO Auto-generated method stub } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java index 30474f285..a5648612f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/MakeChanges.java @@ -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 extends ServerToClientMessage return model; } - private static void saveOrUpdateModelAfterChanges(RemoteModelDao dao, T model, String oldUuid, String uuid, Criterion orCriterion) { + private static void saveOrUpdateModelAfterChanges(RemoteModelDao 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 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 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 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) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java index 81a827694..f06bd16c9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java @@ -42,7 +42,7 @@ public class NowBriefed extends ServerToClientMessage } @Override - public void processMessage() { + public void processMessage(String serverTime) { if (pushedAt > 0) { if (TextUtils.isEmpty(uuid)) { if (!TextUtils.isEmpty(taskId)) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java index eeaac82d0..d4a51febb 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java @@ -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"; diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java index f2798fe5e..2f6387830 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java @@ -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");