import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostBuilder;
import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.PostReplyBuilder;
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;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
}
/**
- * Removes the given Sone from the downloader.
- *
- * @param sone
- * The Sone to stop watching
- */
- public void removeSone(Sone sone) {
- if (sones.remove(sone)) {
- freenetInterface.unregisterUsk(sone);
- }
- }
-
- /**
* Fetches the updated Sone. This method is a callback method for
* {@link FreenetInterface#registerUsk(Sone, SoneDownloader)}.
*
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);
}
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 {
}
}
- 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");
return null;
}
try {
- profile.addField(fieldName).setValue(fieldValue);
+ profile.addField(fieldName.trim()).setValue(fieldValue);
} catch (IllegalArgumentException iae1) {
logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
return null;
try {
PostBuilder postBuilder = core.postBuilder();
/* TODO - parse time correctly. */
- postBuilder.withId(postId).from(sone).withTime(Long.parseLong(postTime)).withText(postText);
+ postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(core.getSone(postRecipientId));
+ postBuilder.to(postRecipientId);
}
posts.add(postBuilder.build());
} catch (NumberFormatException nfe1) {
try {
PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
/* TODO - parse time correctly. */
- postReplyBuilder.withId(replyId).from(sone).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
} catch (NumberFormatException nfe1) {
/* TODO - mark Sone as bad. */
String title = albumXml.getValue("title", null);
String description = albumXml.getValue("description", "");
String albumImageId = albumXml.getValue("album-image", null);
- if ((id == null) || (title == null) || (description == null)) {
+ if ((id == null) || (title == null)) {
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
return null;
}
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 {
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);
+ Image image = core.getImage(imageId).modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
+ image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
+ image = image.modify().setWidth(imageWidth).setHeight(imageHeight).update();
album.addImage(image);
}
}
- album.setAlbumImage(albumImageId);
+ album.modify().setAlbumImage(albumImageId).update();
}
}
sone.setReplies(replies);
sone.setLikePostIds(likedPostIds);
sone.setLikeReplyIds(likedReplyIds);
- sone.setAlbums(topLevelAlbums);
+ for (Album album : topLevelAlbums) {
+ sone.getRootAlbum().addAlbum(album);
+ }
}
return sone;
}
}
+ public class FetchSoneWithUri implements Runnable {
+
+ private final Sone sone;
+
+ public FetchSoneWithUri(Sone sone) {
+ this.sone = sone;
+ }
+
+ @Override
+ public void run() {
+ fetchSone(sone, sone.getRequestUri());
+ }
+
+ }
+
+ public class FetchSone implements Runnable {
+
+ private final Sone sone;
+
+ public FetchSone(Sone sone) {
+ this.sone = sone;
+ }
+
+ @Override
+ public void run() {
+ fetchSone(sone);
+ }
+
+ }
+
}