Permalink
Browse files

keep previous feed in record, while the new one is downloaded

  • Loading branch information...
mic mic
mic authored and mic committed Feb 23, 2013
1 parent aa582ac commit e0dacd4ba6b16c1701a351cd84802c33944feab8
@@ -200,7 +200,13 @@ public JSONObject getRecord(String user) {
public void putRecord(JSONObject record) {
try {
- records.put(record.getString("id"), record);
+ String id = record.getString("id");
+ JSONObject old = records.get(id);
+ if (old != null) {
+ String prev = old.getString("uri");
+ record.put("prev", prev);
+ }
+ records.put(id, record);
} catch (JSONException e1) {
e1.printStackTrace();
}
@@ -188,21 +188,30 @@ public String seed(File file) {
.getString("uri"));
File dbFile = new File(CACHE_FOLDER + File.separator
+ latestHash + ".json");
- System.out.println("Getting feed: " + dbFile.getAbsolutePath());
- JSONObject db = new JSONObject(new JSONTokener(new FileReader(
- dbFile)));
-
- JSONArray items = db.getJSONArray("items");
- for (int i = 0; i < items.length(); ++i) {
- JSONObject item = items.getJSONObject(i);
- ActivityEntry entry = (ActivityEntry) CONVERTER
- .convertToObject(item, ActivityEntry.class);
- result.add(entry);
+ if (! dbFile.exists() && record.has("prev")) {
+ latestHash = FileSharing.getHashFromMagnetURI(record
+ .getString("prev"));
+ dbFile = new File(CACHE_FOLDER + File.separator
+ + latestHash + ".json");
+ }
+ if (dbFile.exists()) {
+ System.out.println("Getting feed: " + dbFile.getAbsolutePath());
+ JSONObject db = new JSONObject(new JSONTokener(new FileReader(
+ dbFile)));
+
+ JSONArray items = db.getJSONArray("items");
+ for (int i = 0; i < items.length(); ++i) {
+ JSONObject item = items.getJSONObject(i);
+ ActivityEntry entry = (ActivityEntry) CONVERTER
+ .convertToObject(item, ActivityEntry.class);
+ result.add(entry);
+ }
+ System.out.println("Feed loaded");
+ } else {
+ System.out.println("Feed not found");
}
- System.out.println("Feed loaded");
} catch (Exception e) {
- // e.printStackTrace();
- System.out.println("Feed not found");
+ e.printStackTrace();
}
}
return result;

0 comments on commit e0dacd4

Please sign in to comment.