diff --git a/api/src/com/todoroo/astrid/data/User.java b/api/src/com/todoroo/astrid/data/User.java index c885edf36..e12cd9ca7 100644 --- a/api/src/com/todoroo/astrid/data/User.java +++ b/api/src/com/todoroo/astrid/data/User.java @@ -70,6 +70,10 @@ public final class User extends RemoteModel { public static final LongProperty PUSHED_AT = new LongProperty( TABLE, PUSHED_AT_PROPERTY_NAME); + /** Pushed at date */ + public static final LongProperty TASKS_PUSHED_AT = new LongProperty( + TABLE, "tasks_pushed_at"); + /** Friendship status. One of the STATUS constants below */ public static final StringProperty STATUS = new StringProperty( TABLE, "status"); @@ -94,6 +98,7 @@ public final class User extends RemoteModel { defaultValues.put(EMAIL.name, ""); defaultValues.put(PICTURE.name, ""); defaultValues.put(PUSHED_AT.name, 0L); + defaultValues.put(TASKS_PUSHED_AT.name, 0L); defaultValues.put(UUID.name, NO_UUID); defaultValues.put(STATUS.name, ""); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java index 7c74ee98f..5574c7830 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java @@ -16,6 +16,7 @@ public class BriefMe extends ClientToServerMessage BriefMe instantiateBriefMeForClass(Class cls, String pushedAtKey) { long pushedAt = Preferences.getLong(pushedAtKey, 0); @@ -37,7 +38,7 @@ public class BriefMe extends ClientToServerMessage 0) { - for (int i = 0; i < extraParameters.length - 1; i++) { + for (int i = 0; i < extraParameters.length - 1; i+=2) { try { String key = (String) extraParameters[i]; Object value = extraParameters[i + 1]; diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java index 56da52d10..78c89799a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NowBriefed.java @@ -14,6 +14,7 @@ import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.User; @SuppressWarnings("nls") public class NowBriefed extends ServerToClientMessage { @@ -25,6 +26,7 @@ public class NowBriefed extends ServerToClientMessage private final String uuid; private final String taskId; private final String tagId; + private final String userId; private long pushedAt; public NowBriefed(JSONObject json, RemoteModelDao dao) { @@ -33,6 +35,7 @@ public class NowBriefed extends ServerToClientMessage this.uuid = json.optString("uuid"); this.taskId = json.optString(BriefMe.TASK_ID_KEY); this.tagId = json.optString(BriefMe.TAG_ID_KEY); + this.userId = json.optString(BriefMe.USER_ID_KEY); this.dao = dao; try { this.pushedAt = DateUtilities.parseIso8601(json.optString("pushed_at")); @@ -67,6 +70,12 @@ public class NowBriefed extends ServerToClientMessage if (template.getSetValues() != null) PluginServices.getTagDataDao().update(TagData.UUID.eq(tagId), template); + } else if (!TextUtils.isEmpty(userId)) { + if (NameMaps.TABLE_ID_TASKS.equals(table)) { + User template = new User(); + template.setValue(User.TASKS_PUSHED_AT, pushedAt); + PluginServices.getUserDao().update(User.UUID.eq(userId), template); + } } else { String pushedAtKey = null; if (NameMaps.TABLE_ID_TASKS.equals(table)) diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java index 6ae1c1e82..a8f0ba323 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java @@ -191,7 +191,10 @@ public class PersonViewFragment extends TaskListFragment { return; if (user != null) { long pushedAt = user.getValue(User.PUSHED_AT); - if(DateUtilities.now() - pushedAt > DateUtilities.ONE_HOUR / 2) + long tasksPushedAt = user.getValue(User.TASKS_PUSHED_AT); + + if((DateUtilities.now() - pushedAt > DateUtilities.ONE_HOUR / 2) || + (DateUtilities.now() - tasksPushedAt > DateUtilities.ONE_HOUR / 2)) refreshData(); } } @@ -226,14 +229,14 @@ public class PersonViewFragment extends TaskListFragment { @Override public void runOnErrors(List errors) {/**/} }; - long pushedAt = user.getValue(User.PUSHED_AT); + long pushedAt = user.getValue(User.TASKS_PUSHED_AT); JSONArray existingTasks = new JSONArray(); TodorooCursor tasksCursor = (TodorooCursor) taskAdapter.getCursor(); for (tasksCursor.moveToFirst(); !tasksCursor.isAfterLast(); tasksCursor.moveToNext()) { existingTasks.put(tasksCursor.get(Task.UUID)); } - BriefMe briefMe = new BriefMe(Task.class, null, pushedAt, "user_id", user.getValue(User.UUID), "existing_tasks", existingTasks); //$NON-NLS-1$//$NON-NLS-2$ + BriefMe briefMe = new BriefMe(Task.class, null, pushedAt, BriefMe.USER_ID_KEY, user.getValue(User.UUID), "existing_task_ids", existingTasks); //$NON-NLS-1$ ActFmSyncThread.getInstance().enqueueMessage(briefMe, callback); } } diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index a9b2deef5..040b8b72f 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -153,7 +153,7 @@ public class Database extends AbstractDatabase { append(')'); database.execSQL(sql.toString()); sql.setLength(0); - + sql.append("CREATE INDEX IF NOT EXISTS hist_tag_id ON "). append(History.TABLE).append('('). append(History.TAG_ID.name). @@ -394,6 +394,7 @@ public class Database extends AbstractDatabase { case 32: tryExecSQL("DROP TABLE " + History.TABLE.name); tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES)); + tryExecSQL(addColumnSql(User.TABLE, User.TASKS_PUSHED_AT, visitor, null)); return true; }