From: David ‘Bombe’ Roden Date: Sun, 7 Dec 2014 10:37:44 +0000 (+0100) Subject: Remove post reply management from Sone. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d15563b5b582b71366a52a361537c06cd52ae55b;p=Sone.git Remove post reply management from Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 2e1b5fb..f39f8eb 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1024,7 +1024,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, 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; @@ -1044,7 +1043,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } database.removePostReply(reply); markReplyKnown(reply); - sone.removeReply(reply); touchConfiguration(); } diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index d2914da..6056a7f 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -191,15 +191,14 @@ public class SoneParser { } soneBuilder.withPosts(posts); } - Sone sone = soneBuilder.build(); /* parse replies. */ SimpleXML repliesXml = soneXml.getNode("replies"); - Set replies = new HashSet(); 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 replies = new HashSet(); for (SimpleXML replyXml : repliesXml.getNodes("reply")) { String replyId = replyXml.getValue("id", null); String replyPostId = replyXml.getValue("post-id", null); @@ -207,21 +206,23 @@ public class SoneParser { 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"); @@ -326,7 +327,6 @@ public class SoneParser { /* atomic setter operation on the Sone. */ synchronized (sone) { sone.setProfile(profile); - sone.setReplies(replies); sone.setLikePostIds(likedPostIds); sone.setLikeReplyIds(likedReplyIds); for (Album album : topLevelAlbums) { diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 2cf8bf6..bc90b12 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -350,32 +350,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { Set 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 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 diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java index bc19d4d..a2f1333 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java @@ -7,6 +7,7 @@ import java.util.HashSet; 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; @@ -23,6 +24,7 @@ public abstract class AbstractSoneBuilder implements SoneBuilder { protected long lastUpdated; protected Client client; protected final Collection posts = new HashSet(); + protected final Collection postReplies = new HashSet(); @Override public SoneBuilder from(Identity identity) { @@ -55,6 +57,13 @@ public abstract class AbstractSoneBuilder implements SoneBuilder { return this; } + @Override + public SoneBuilder withPostReplies(Collection 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), diff --git a/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java index 018ba32..0401a30 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java @@ -126,19 +126,6 @@ public class IdOnlySone implements Sone { } @Override - public Sone setReplies(Collection replies) { - return this; - } - - @Override - public void addReply(PostReply reply) { - } - - @Override - public void removeReply(PostReply reply) { - } - - @Override public Set getLikedPostIds() { return emptySet(); } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java index 142f4a2..eb8bbe5 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java @@ -98,7 +98,7 @@ public class SoneImpl implements LocalSone { private final Collection posts = new HashSet(); /** All replies. */ - private final Set replies = new CopyOnWriteArraySet(); + private final Set replies = new HashSet(); /** The IDs of all liked posts. */ private final Set likedPostIds = new CopyOnWriteArraySet(); @@ -121,7 +121,7 @@ public class SoneImpl implements LocalSone { * @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 posts) { + public SoneImpl(Database database, Identity identity, boolean local, long time, Client client, Collection posts, Collection postReplies) { this.database = database; this.id = identity.getId(); this.identity = identity; @@ -129,6 +129,7 @@ public class SoneImpl implements LocalSone { this.time = time; this.client = client; this.posts.addAll(posts); + this.replies.addAll(postReplies); } // diff --git a/src/main/java/net/pterodactylus/sone/database/SoneBuilder.java b/src/main/java/net/pterodactylus/sone/database/SoneBuilder.java index 0fdeacf..5fb5fed 100644 --- a/src/main/java/net/pterodactylus/sone/database/SoneBuilder.java +++ b/src/main/java/net/pterodactylus/sone/database/SoneBuilder.java @@ -4,6 +4,7 @@ import java.util.Collection; 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; @@ -21,6 +22,7 @@ public interface SoneBuilder { SoneBuilder using(Client client); SoneBuilder withPosts(Collection posts); + SoneBuilder withPostReplies(Collection postReplies); Sone build() throws IllegalStateException; diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemorySoneBuilder.java b/src/main/java/net/pterodactylus/sone/database/memory/MemorySoneBuilder.java index 355d2ad..3cdb120 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemorySoneBuilder.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemorySoneBuilder.java @@ -21,7 +21,7 @@ public class MemorySoneBuilder extends AbstractSoneBuilder { @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); } }