if (postId == null) {
break;
}
+ String postRecipientId = configuration.getStringValue(postPrefix + "/Recipient").getValue(null);
long postTime = configuration.getLongValue(postPrefix + "/Time").getValue((long) 0);
String postText = configuration.getStringValue(postPrefix + "/Text").getValue(null);
if ((postTime == 0) || (postText == null)) {
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- posts.add(getPost(postId).setSone(sone).setTime(postTime).setText(postText));
+ Post post = getPost(postId).setSone(sone).setTime(postTime).setText(postText);
+ if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
+ post.setRecipient(getSone(postRecipientId));
+ }
+ posts.add(post);
}
/* load replies. */
for (Post post : sone.getPosts()) {
String postPrefix = sonePrefix + "/Posts/" + postCounter++;
configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
+ if (post.getRecipient() != null) {
+ configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipient().getId());
+ }
configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
}
} 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)) {
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 });
/** The Sone this post belongs to. */
private volatile Sone sone;
+ /** The Sone of the recipient. */
+ private volatile Sone recipient;
+
/** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
private volatile long time;
}
/**
+ * Returns the recipient of this post, if any.
+ *
+ * @return The recipient of this post, or {@code null}
+ */
+ public Sone getRecipient() {
+ return recipient;
+ }
+
+ /**
+ * Sets the recipient of this post.
+ *
+ * @param recipient
+ * The recipient of this post, or {@code null}
+ * @return This post (for method chaining)
+ */
+ public Post setRecipient(Sone recipient) {
+ this.recipient = recipient;
+ return this;
+ }
+
+ /**
* Returns the time of the post.
*
* @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
<%foreach currentSone.posts post>
<post>
<id><% post.id|xml></id>
+ <recipient><%ifnull !post.recipient><% post.recipient.id|xml><%/if></recipient>
<time><% post.time></time>
<text><% post.text|xml></text>
</post>