If PDV tasks aren't created by or responsible by current user, don't synchronize them

pull/14/head
Tim Su 14 years ago
parent 5472e0da2c
commit 8697f99cab

@ -21,10 +21,10 @@ import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.StoreObject; import com.todoroo.astrid.model.StoreObject;
@ -113,18 +113,20 @@ public final class ProducteevDataService {
/** /**
* Searches for a local task with same remote id, updates this task's id * Searches for a local task with same remote id, updates this task's id
* @param remoteTask * @param remoteTask
* @return true if found local match
*/ */
public void findLocalMatch(ProducteevTaskContainer remoteTask) { public boolean findLocalMatch(ProducteevTaskContainer remoteTask) {
if(remoteTask.task.getId() != Task.NO_ID) if(remoteTask.task.getId() != Task.NO_ID)
return; return true;
TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID). TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID).
join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), join(ProducteevDataService.METADATA_JOIN).where(Criterion.and(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
ProducteevTask.ID.eq(remoteTask.pdvTask.getValue(ProducteevTask.ID))))); ProducteevTask.ID.eq(remoteTask.pdvTask.getValue(ProducteevTask.ID)))));
try { try {
if(cursor.getCount() == 0) if(cursor.getCount() == 0)
return; return false;
cursor.moveToFirst(); cursor.moveToFirst();
remoteTask.task.setId(cursor.get(Task.ID)); remoteTask.task.setId(cursor.get(Task.ID));
return true;
} finally { } finally {
cursor.close(); cursor.close();
} }

@ -195,6 +195,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
// load user information // load user information
JSONObject user = invoker.usersView(null).getJSONObject("user"); JSONObject user = invoker.usersView(null).getJSONObject("user");
saveUserData(user); saveUserData(user);
long userId = user.getLong("id_user");
String lastServerSync = Preferences.getStringValue(ProducteevUtilities.PREF_SERVER_LAST_SYNC); String lastServerSync = Preferences.getStringValue(ProducteevUtilities.PREF_SERVER_LAST_SYNC);
if(lastServerSync != null) if(lastServerSync != null)
@ -214,7 +215,17 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
JSONArray tasks = invoker.tasksShowList(dashboardId, lastServerSync); JSONArray tasks = invoker.tasksShowList(dashboardId, lastServerSync);
for(int i = 0; i < tasks.length(); i++) { for(int i = 0; i < tasks.length(); i++) {
ProducteevTaskContainer remote = parseRemoteTask(tasks.getJSONObject(i)); ProducteevTaskContainer remote = parseRemoteTask(tasks.getJSONObject(i));
dataService.findLocalMatch(remote); boolean foundLocal = dataService.findLocalMatch(remote);
// if creator & responsible != current user, skip / delete it
if(userId != remote.pdvTask.getValue(ProducteevTask.CREATOR_ID) &&
userId != remote.pdvTask.getValue(ProducteevTask.RESPONSIBLE_ID)) {
if(foundLocal)
remote.task.setValue(Task.DELETION_DATE, DateUtilities.now());
else
continue;
}
remoteTasks.add(remote); remoteTasks.add(remote);
} }
} }

@ -106,7 +106,7 @@ public final class UpgradeService {
"Restored tag hiding when tag begins with underscore (_)", "Restored tag hiding when tag begins with underscore (_)",
"FROYO: disabled moving app to SD card, it would break alarms and widget", "FROYO: disabled moving app to SD card, it would break alarms and widget",
"Also gone: a couple force closes, bugs with repeating tasks", "Also gone: a couple force closes, bugs with repeating tasks",
"... enjoy! - we astrid team", "... enjoy! - we <3 astrid team",
}); });
if(from > 135 && from <= 144) if(from > 135 && from <= 144)
newVersionString(changeLog, "3.0.6 (8/4/10)", new String[] { newVersionString(changeLog, "3.0.6 (8/4/10)", new String[] {

Loading…
Cancel
Save