From b948fb2f52aa0ac86f13f5e0cbb1744e0e76624d Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 22 Oct 2012 14:04:12 -0700 Subject: [PATCH] Fetch suggested users along with regular users --- .../astrid/actfm/sync/ActFmSyncService.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 64366dd90..95eeae056 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -867,22 +867,31 @@ public final class ActFmSyncService { return result.optInt("time", 0); } + private void saveUsers(JSONArray users, HashSet ids) throws JSONException { + for (int i = 0; i < users.length(); i++) { + JSONObject userObject = users.getJSONObject(i); + ids.add(userObject.optLong("id")); + actFmDataService.saveUserData(userObject); } + + } + public int fetchUsers() throws JSONException, IOException { if (!checkForToken()) return 0; JSONObject result = actFmInvoker.invoke("user_list", "token", token); + JSONObject suggestedResult = actFmInvoker.invoke("suggested_user_list", + "token", token); JSONArray users = result.getJSONArray("list"); + JSONArray suggestedUsers = suggestedResult.getJSONArray("list"); + HashSet ids = new HashSet(); - if (users.length() > 0) + if (users.length() > 0 || suggestedUsers.length() > 0) Preferences.setBoolean(R.string.p_show_friends_view, true); - for (int i = 0; i < users.length(); i++) { - JSONObject userObject = users.getJSONObject(i); - ids.add(userObject.optLong("id")); - actFmDataService.saveUserData(userObject); - } + saveUsers(users, ids); + saveUsers(suggestedUsers, ids); Long[] idsArray = ids.toArray(new Long[ids.size()]); actFmDataService.userDao.deleteWhere(Criterion.not(User.REMOTE_ID.in(idsArray)));