diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/SyncDatabaseListener.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/SyncDatabaseListener.java index 4ecaa9a31..54c5aa533 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/SyncDatabaseListener.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/SyncDatabaseListener.java @@ -22,9 +22,12 @@ public class SyncDatabaseListener implements ModelUpd @Override public void onModelUpdated(MTYPE model) { - queue.add(ChangesHappened.instantiateChangesHappened(model.getId(), modelType)); - synchronized(monitor) { - monitor.notifyAll(); + ChangesHappened ch = ChangesHappened.instantiateChangesHappened(model.getId(), modelType); + if (ch.numChanges() > 0) { + queue.add(ch); + synchronized(monitor) { + monitor.notifyAll(); + } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index 3f158a891..265cc96d2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -105,7 +105,7 @@ public class ChangesHappened 0) { try { JSONObject proofText = new JSONObject(); proofText.put("id", -1); 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 841ddd554..ae15fa191 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 @@ -52,6 +52,9 @@ public class MakeChanges extends ServerToClientMessage } } + StringProperty uuidProperty = (StringProperty) NameMaps.serverColumnNameToLocalProperty(table, "uuid"); + model.setValue(uuidProperty, uuid); + if (model.getSetValues().size() > 0) { model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); if (dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), model) <= 0) { // If update doesn't update rows. create a new model diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java index 55d8448cf..b28cd152c 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java @@ -1,9 +1,10 @@ package com.todoroo.astrid.sync; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmSyncThread.ModelType; @@ -76,6 +77,32 @@ public class SyncMessageTest extends NewSyncTestCase { } } + public void testMakeChangesMakesNewTasks() { + try { + JSONObject makeChanges = getMakeChanges(); + makeChanges.put("uuid", "1"); + ServerToClientMessage message = ServerToClientMessage.instantiateMessage(makeChanges); + message.processMessage(); + + TodorooCursor cursor = taskDao.query(Query.select(Task.ID, Task.UUID, Task.TITLE, Task.IMPORTANCE).where(Task.UUID.eq("1"))); + try { + assertEquals(1, cursor.getCount()); + cursor.moveToFirst(); + Task t = new Task(cursor); + + assertEquals(MAKE_CHANGES_TITLE, t.getValue(Task.TITLE)); + assertEquals(Task.IMPORTANCE_DO_OR_DIE, t.getValue(Task.IMPORTANCE).intValue()); + assertEquals("1", t.getValue(Task.UUID)); + } finally { + cursor.close(); + } + + } catch (JSONException e) { + e.printStackTrace(); + fail("JSONException"); + } + } + public void testMakeChangesToPushedAtValues() { try { long date = DateUtilities.now();