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 20adf6af0..c423a86c5 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 @@ -1,17 +1,62 @@ package com.todoroo.astrid.actfm.sync.messages; +import java.util.ArrayList; + +import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; +import android.text.TextUtils; + +import com.todoroo.andlib.data.AbstractModel; +import com.todoroo.andlib.service.Autowired; +import com.todoroo.andlib.service.DependencyInjectionService; +import com.todoroo.astrid.dao.OutstandingEntryDao; +import com.todoroo.astrid.dao.TagOutstandingDao; +import com.todoroo.astrid.dao.TaskOutstandingDao; + public class AcknowledgeChange extends ServerToClientMessage { + @Autowired + private TaskOutstandingDao taskOutstandingDao; + + @Autowired + private TagOutstandingDao tagOutstandingDao; + public AcknowledgeChange(JSONObject json) { super(json); - throw new RuntimeException("No constructor for AcknowledgeChange implemented"); //$NON-NLS-1$ + DependencyInjectionService.getInstance().inject(this); } @Override + @SuppressWarnings("nls") public void processMessage() { - // TODO Auto-generated method stub + JSONArray idsArray = json.optJSONArray("ids"); + String table = json.optString("table"); + if (idsArray != null && !TextUtils.isEmpty(table)) { + OutstandingEntryDao dao = null; + if (NameMaps.SERVER_TABLE_TASKS.equals(table)) + dao = taskOutstandingDao; + else if (NameMaps.SERVER_TABLE_TAGS.equals(table)) + dao = tagOutstandingDao; + + if (dao == null) + return; + + ArrayList idsList = new ArrayList(); + for (int i = 0; i < idsArray.length(); i++) { + try { + Long id = idsArray.getLong(i); + if (id <= 0) + continue; + + idsList.add(id); + } catch (JSONException e) { + // + } + } + dao.deleteWhere(AbstractModel.ID_PROPERTY.in(idsList.toArray(new Long[idsList.size()]))); + } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java index b05e7d657..4c2552ec7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java @@ -18,12 +18,16 @@ public class NameMaps { private static final Map TABLE_LOCAL_TO_SERVER; private static final Map TABLE_SERVER_TO_LOCAL; + public static final String SERVER_TABLE_TASKS = "tasks"; + public static final String SERVER_TABLE_TAGS = "tags"; + public static final String SERVER_TABLE_USERS = "users"; + static { // Hardcoded local tables mapped to corresponding server names TABLE_LOCAL_TO_SERVER = new HashMap(); - TABLE_LOCAL_TO_SERVER.put(Task.TABLE, "tasks"); - TABLE_LOCAL_TO_SERVER.put(TagData.TABLE, "tags"); - TABLE_LOCAL_TO_SERVER.put(User.TABLE, "users"); + TABLE_LOCAL_TO_SERVER.put(Task.TABLE, SERVER_TABLE_TASKS); + TABLE_LOCAL_TO_SERVER.put(TagData.TABLE, SERVER_TABLE_TAGS); + TABLE_LOCAL_TO_SERVER.put(User.TABLE, SERVER_TABLE_USERS); // Reverse the mapping to construct the server to local map TABLE_SERVER_TO_LOCAL = AndroidUtilities.reverseMap(TABLE_LOCAL_TO_SERVER); 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 fbb4bdf98..47f21ab48 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 @@ -12,9 +12,10 @@ public abstract class ServerToClientMessage { private static final String TYPE_DOUBLE_CHECK = "DoubleCheck"; private static final String TYPE_DEBUG = "Debug"; - @SuppressWarnings("unused") + protected final JSONObject json; + public ServerToClientMessage(JSONObject json) { - // + this.json = json; } public static ServerToClientMessage instantiateMessage(JSONObject json) {