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 4b72884e5..9db8fde4a 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 @@ -163,14 +163,21 @@ public class MakeChanges extends ServerToClientMessage @Override public void performChanges() { JSONArray addTags = changes.optJSONArray("tag_added"); - if (addTags != null) { - TagService tagService = TagService.getInstance(); - for (int i = 0; i < addTags.length(); i++) { - try { - String tagUuid = addTags.getString(i); - tagService.createLink(model.getId(), uuid, tagUuid); - } catch (JSONException e) { - // + if (addTags != null && addTags.length() > 0) { + if (!model.isSaved()) { // We don't have the local task id + long localId = dao.localIdFromUuid(uuid); + model.setId(localId); + } + + if (model.isSaved()) { + TagService tagService = TagService.getInstance(); + for (int i = 0; i < addTags.length(); i++) { + try { + String tagUuid = addTags.getString(i); + tagService.createLink(model.getId(), uuid, tagUuid); + } catch (JSONException e) { + // + } } } } diff --git a/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java b/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java index dca9937f5..1e2d61310 100644 --- a/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java +++ b/astrid/src/com/todoroo/astrid/dao/RemoteModelDao.java @@ -1,5 +1,6 @@ package com.todoroo.astrid.dao; +import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; @@ -30,6 +31,12 @@ public class RemoteModelDao extends DatabaseDao... properties) { TodorooCursor cursor = fetchItem(uuid, properties); return returnFetchResult(cursor); @@ -54,5 +61,22 @@ public class RemoteModelDao extends DatabaseDao(cursor, properties); } + /** + * Get the local id + * @param uuid + * @return + */ + public long localIdFromUuid(String uuid) { + TodorooCursor cursor = query(Query.select(AbstractModel.ID_PROPERTY).where(RemoteModel.UUID_PROPERTY.eq(uuid))); + try { + if (cursor.getCount() == 0) + return AbstractModel.NO_ID; + cursor.moveToFirst(); + return cursor.get(AbstractModel.ID_PROPERTY); + } finally { + cursor.close(); + } + } + }