X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=fa0063e4898e5dc335356da450a890239cb30d0d;hb=4316b669b28d294dd2b4b9a34e45f080c77037fe;hp=2310aca328b3e3574cf6722639472ac9b57f170b;hpb=5c5ef0964da82ea0f677ea0e7f24901f8e31af88;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 2310aca..fa0063e 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -114,11 +114,25 @@ public class SoneDownloader extends AbstractService { * The Sone to fetch */ public void fetchSone(Sone sone) { + fetchSone(sone, sone.getRequestUri()); + } + + /** + * Fetches the updated Sone. This method can be used to fetch a Sone from a + * specific URI (which happens when {@link Core#isSoneRescueMode() „Sone + * rescue mode“} is active). + * + * @param sone + * The Sone to fetch + * @param soneUri + * The URI to fetch the Sone from + */ + public void fetchSone(Sone sone, FreenetURI soneUri) { if (core.getSoneStatus(sone) == SoneStatus.downloading) { return; } - logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, sone.getRequestUri().setMetaString(new String[] { "sone.xml" }) }); - FreenetURI requestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" }); + logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, soneUri }); + FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" }); core.setSoneStatus(sone, SoneStatus.downloading); try { Pair fetchResults = freenetInterface.fetchUri(requestUri); @@ -155,6 +169,7 @@ public class SoneDownloader extends AbstractService { soneInputStream = soneBucket.getInputStream(); Sone parsedSone = parseSone(originalSone, soneInputStream); if (parsedSone != null) { + parsedSone.setLatestEdition(requestUri.getEdition()); if (requestUri.getKeyType().equals("USK")) { parsedSone.setRequestUri(requestUri.setMetaString(new String[0])); } else { @@ -280,6 +295,7 @@ public class SoneDownloader extends AbstractService { } else { for (SimpleXML postXml : postsXml.getNodes("post")) { String postId = postXml.getValue("id", null); + String postRecipientId = postXml.getValue("recipient", null); String postTime = postXml.getValue("time", null); String postText = postXml.getValue("text", null); if ((postId == null) || (postTime == null) || (postText == null)) { @@ -288,7 +304,11 @@ public class SoneDownloader extends AbstractService { return null; } try { - posts.add(core.getPost(postId).setSone(sone).setTime(Long.parseLong(postTime)).setText(postText)); + Post post = core.getPost(postId).setSone(sone).setTime(Long.parseLong(postTime)).setText(postText); + if ((postRecipientId != null) && (postRecipientId.length() == 43)) { + post.setRecipient(core.getSone(postRecipientId)); + } + posts.add(post); } catch (NumberFormatException nfe1) { /* TODO - mark Sone as bad. */ logger.log(Level.WARNING, "Downloaded post for Sone %s with invalid time: %s", new Object[] { sone, postTime }); @@ -357,6 +377,7 @@ public class SoneDownloader extends AbstractService { sone.setPosts(posts); sone.setReplies(replies); sone.setLikePostIds(likedPostIds); + sone.setLikeReplyIds(likedReplyIds); } return sone;