final PostReply reply = postReplyBuilder.build();
database.storePostReply(reply);
eventBus.post(new NewPostReplyFoundEvent(reply));
- sone.addReply(reply);
touchConfiguration();
localElementTicker.schedule(new MarkReplyKnown(reply), 10, TimeUnit.SECONDS);
return reply;
}
database.removePostReply(reply);
markReplyKnown(reply);
- sone.removeReply(reply);
touchConfiguration();
}
}
soneBuilder.withPosts(posts);
}
- Sone sone = soneBuilder.build();
/* parse replies. */
SimpleXML repliesXml = soneXml.getNode("replies");
- Set<PostReply> replies = new HashSet<PostReply>();
if (repliesXml == null) {
/* TODO - mark Sone as bad. */
- logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", sone));
+ logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", originalSone));
} else {
+ Set<PostReply> replies = new HashSet<PostReply>();
for (SimpleXML replyXml : repliesXml.getNodes("reply")) {
String replyId = replyXml.getValue("id", null);
String replyPostId = replyXml.getValue("post-id", null);
String replyText = replyXml.getValue("text", null);
if ((replyId == null) || (replyPostId == null) || (replyTime == null) || (replyText == null)) {
/* TODO - mark Sone as bad. */
- logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", sone, replyId, replyPostId, replyTime, replyText));
+ logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", originalSone, replyId, replyPostId, replyTime, replyText));
return null;
}
try {
PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
/* TODO - parse time correctly. */
- postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+ postReplyBuilder.withId(replyId).from(originalSone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
} catch (NumberFormatException nfe1) {
/* TODO - mark Sone as bad. */
- logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with invalid time: %s", sone, replyTime));
+ logger.log(Level.WARNING, String.format("Downloaded reply for Sone %s with invalid time: %s", originalSone, replyTime));
return null;
}
}
+ soneBuilder.withPostReplies(replies);
}
+ Sone sone = soneBuilder.build();
/* parse liked post IDs. */
SimpleXML likePostIdsXml = soneXml.getNode("post-likes");
/* atomic setter operation on the Sone. */
synchronized (sone) {
sone.setProfile(profile);
- sone.setReplies(replies);
sone.setLikePostIds(likedPostIds);
sone.setLikeReplyIds(likedReplyIds);
for (Album album : topLevelAlbums) {
Set<PostReply> getReplies();
/**
- * Sets all replies of this Sone at once.
- *
- * @param replies
- * The new (and only) replies of this Sone
- * @return This Sone (for method chaining)
- */
- Sone setReplies(Collection<PostReply> replies);
-
- /**
- * Adds a reply to this Sone. If the given reply was not made by this Sone,
- * nothing is added to this Sone.
- *
- * @param reply
- * The reply to add
- */
- void addReply(PostReply reply);
-
- /**
- * Removes a reply from this Sone.
- *
- * @param reply
- * The reply to remove
- */
- void removeReply(PostReply reply);
-
- /**
* Returns the IDs of all liked posts.
*
* @return All liked posts’ IDs
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.database.SoneBuilder;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
protected long lastUpdated;
protected Client client;
protected final Collection<Post> posts = new HashSet<Post>();
+ protected final Collection<PostReply> postReplies = new HashSet<PostReply>();
@Override
public SoneBuilder from(Identity identity) {
return this;
}
+ @Override
+ public SoneBuilder withPostReplies(Collection<PostReply> postReplies) {
+ this.postReplies.clear();
+ this.postReplies.addAll(postReplies);
+ return this;
+ }
+
protected void validate() throws IllegalStateException {
checkState(identity != null, "identity must not be null");
checkState(!local || (identity instanceof OwnIdentity),
}
@Override
- public Sone setReplies(Collection<PostReply> replies) {
- return this;
- }
-
- @Override
- public void addReply(PostReply reply) {
- }
-
- @Override
- public void removeReply(PostReply reply) {
- }
-
- @Override
public Set<String> getLikedPostIds() {
return emptySet();
}
private final Collection<Post> posts = new HashSet<Post>();
/** All replies. */
- private final Set<PostReply> replies = new CopyOnWriteArraySet<PostReply>();
+ private final Set<PostReply> replies = new HashSet<PostReply>();
/** The IDs of all liked posts. */
private final Set<String> likedPostIds = new CopyOnWriteArraySet<String>();
* @param local
* {@code true} if the Sone is a local Sone, {@code false} otherwise
*/
- public SoneImpl(Database database, Identity identity, boolean local, long time, Client client, Collection<Post> posts) {
+ public SoneImpl(Database database, Identity identity, boolean local, long time, Client client, Collection<Post> posts, Collection<PostReply> postReplies) {
this.database = database;
this.id = identity.getId();
this.identity = identity;
this.time = time;
this.client = client;
this.posts.addAll(posts);
+ this.replies.addAll(postReplies);
}
//
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.wot.Identity;
SoneBuilder using(Client client);
SoneBuilder withPosts(Collection<Post> posts);
+ SoneBuilder withPostReplies(Collection<PostReply> postReplies);
Sone build() throws IllegalStateException;
@Override
public Sone build() throws IllegalStateException {
validate();
- return new SoneImpl(database, identity, local, lastUpdated, client, posts);
+ return new SoneImpl(database, identity, local, lastUpdated, client, posts, postReplies);
}
}