private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
/** The configuration. */
- private final Configuration configuration;
+ private Configuration configuration;
/** The identity manager. */
private final IdentityManager identityManager;
//
/**
+ * Sets the configuration to use. This will automatically save the current
+ * configuration to the given configuration.
+ *
+ * @param configuration
+ * The new configuration to use
+ */
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ saveConfiguration();
+ }
+
+ /**
* Returns the options used by the core.
*
* @return The options of the core
* @return The post, or {@code null} if there is no such post
*/
public Post getPost(String postId) {
+ return getPost(postId, true);
+ }
+
+ /**
+ * Returns the post with the given ID, optionally creating a new post.
+ *
+ * @param postId
+ * The ID of the post to get
+ * @param create
+ * {@code true} it create a new post if no post with the given ID
+ * exists, {@code false} to return {@code null}
+ * @return The post, or {@code null} if there is no such post
+ */
+ public Post getPost(String postId, boolean create) {
synchronized (posts) {
Post post = posts.get(postId);
- if (post == null) {
+ if ((post == null) && create) {
post = new Post(postId);
posts.put(postId, post);
}
--edition;
}
logger.log(Level.INFO, "Finished restoring Sone from Freenet, starting Inserter…");
+ saveSone(sone);
coreListenerManager.fireRescuedSone(sone);
soneInserter.start();
}
}
synchronized (newPosts) {
for (Post post : sone.getPosts()) {
+ post.setSone(getSone(post.getSone().getId()));
if (!storedSone.getPosts().contains(post) && !knownPosts.contains(post.getId())) {
- post.setSone(getSone(post.getSone().getId()));
newPosts.add(post.getId());
coreListenerManager.fireNewPostFound(post);
}
}
synchronized (newReplies) {
for (Reply reply : sone.getReplies()) {
+ reply.setSone(getSone(reply.getSone().getId()));
if (!storedSone.getReplies().contains(reply) && !knownReplies.contains(reply.getId())) {
newReplies.add(reply.getId());
coreListenerManager.fireNewReplyFound(reply);
}
}
synchronized (storedSone) {
- storedSone.setTime(sone.getTime());
+ if (!soneRescueMode || (sone.getTime() > storedSone.getTime())) {
+ storedSone.setTime(sone.getTime());
+ }
storedSone.setClient(sone.getClient());
storedSone.setProfile(sone.getProfile());
if (soneRescueMode) {
storedSone.setLikePostIds(sone.getLikedPostIds());
storedSone.setLikeReplyIds(sone.getLikedReplyIds());
}
- storedSone.setLatestEdition(sone.getRequestUri().getEdition());
+ storedSone.setLatestEdition(sone.getLatestEdition());
}
}
}
configuration.getStringValue("KnownReplies/" + replyCounter + "/ID").setValue(null);
}
+ /* now save it. */
+ configuration.save();
+
} catch (ConfigurationException ce1) {
logger.log(Level.SEVERE, "Could not store configuration!", ce1);
}