X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=5f10a482166b99b38451609ca0d8b07fd2b2be57;hb=4e61d9d4c916ff7d314baa2923087203aec3842d;hp=aa2aa99c4870c06dee4c5ead36a91ecfdd33b41c;hpb=4acdae8d247379dedcc5d41c8aded9503fcbaf72;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 aa2aa99..5f10a48 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -35,6 +35,7 @@ import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.data.SoneImpl; import net.pterodactylus.sone.database.PostBuilder; import net.pterodactylus.sone.database.PostReplyBuilder; import net.pterodactylus.util.io.Closer; @@ -166,6 +167,7 @@ public class SoneDownloader extends AbstractService { Sone parsedSone = parseSone(sone, fetchResults.getFetchResult(), fetchResults.getFreenetUri()); if (parsedSone != null) { if (!fetchOnly) { + parsedSone.setStatus((parsedSone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle); core.updateSone(parsedSone); addSone(parsedSone); } @@ -238,7 +240,7 @@ public class SoneDownloader extends AbstractService { return null; } - Sone sone = new Sone(originalSone.getId(), false).setIdentity(originalSone.getIdentity()); + Sone sone = new SoneImpl(originalSone.getId(), originalSone.isLocal()).setIdentity(originalSone.getIdentity()); SimpleXML soneXml; try { @@ -306,16 +308,8 @@ public class SoneDownloader extends AbstractService { } } - String soneInsertUri = soneXml.getValue("insert-uri", null); - if ((soneInsertUri != null) && (sone.getInsertUri() == null)) { - try { - sone.setInsertUri(new FreenetURI(soneInsertUri)); - sone.setLatestEdition(Math.max(sone.getRequestUri().getEdition(), sone.getInsertUri().getEdition())); - } catch (MalformedURLException mue1) { - /* TODO - mark Sone as bad. */ - logger.log(Level.WARNING, String.format("Downloaded Sone %s has invalid insert URI: %s", sone, soneInsertUri), mue1); - return null; - } + if (originalSone.getInsertUri() != null) { + sone.setInsertUri(originalSone.getInsertUri()); } SimpleXML profileXml = soneXml.getNode("profile"); @@ -467,7 +461,7 @@ public class SoneDownloader extends AbstractService { return null; } } - Album album = core.getAlbum(id).setSone(sone).setTitle(title).setDescription(description); + Album album = core.getAlbum(id).setSone(sone).modify().setTitle(title).setDescription(description).update(); if (parent != null) { parent.addAlbum(album); } else { @@ -494,19 +488,17 @@ public class SoneDownloader extends AbstractService { logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString)); return null; } - Image image = core.getImage(imageId).setSone(sone).setKey(imageKey).setCreationTime(creationTime); - image.setTitle(imageTitle).setDescription(imageDescription); - image.setWidth(imageWidth).setHeight(imageHeight); - album.addImage(image); + Image image = album.newImageBuilder().withId(imageId).at(imageKey).created(creationTime).sized(imageWidth, imageHeight).build(); + image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update(); } } - album.setAlbumImage(albumImageId); + album.modify().setAlbumImage(albumImageId).update(); } } /* process avatar. */ if (avatarId != null) { - profile.setAvatar(core.getImage(avatarId, false)); + profile.setAvatar(core.getImage(avatarId).orNull()); } /* okay, apparently everything was parsed correctly. Now import. */ @@ -517,7 +509,9 @@ public class SoneDownloader extends AbstractService { sone.setReplies(replies); sone.setLikePostIds(likedPostIds); sone.setLikeReplyIds(likedReplyIds); - sone.setAlbums(topLevelAlbums); + for (Album album : topLevelAlbums) { + sone.getRootAlbum().addAlbum(album); + } } return sone;