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 920dc33d6..0bd5fc58b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -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 { 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 638749bfa..e9a167135 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 @@ -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 extends ServerToClientMessage private final RemoteModelDao dao; private final String table; + private final long pushedAt; - public MakeChanges(JSONObject json, RemoteModelDao dao) { + public MakeChanges(JSONObject json, RemoteModelDao 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 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)) 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 062fdfa2d..a0a3b1f48 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 @@ -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(json, PluginServices.getTaskDao()); + return new MakeChanges(json, PluginServices.getTaskDao(), pushedAt); else if (NameMaps.TABLE_ID_TAGS.equals(table)) - return new MakeChanges(json, PluginServices.getTagDataDao()); + return new MakeChanges(json, PluginServices.getTagDataDao(), pushedAt); else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table)) - return new MakeChanges(json, null); + return new MakeChanges(json, null, 0); else return null; }