X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FDefaultSone.java;h=6f77fb496f6040e39ce2d6cc8785530f6540f954;hb=550219212ea7809a6575b9d6bbe81030cb6f8618;hp=f519ffaa7a8af73cc189330d5d6fc81f3cacfe07;hpb=2f995a29d8731dc3b3d20e78fd9382be542292ff;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java index f519ffa..6f77fb4 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultSone.java @@ -36,11 +36,15 @@ import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.database.AlbumBuilder; +import net.pterodactylus.sone.database.Database; +import net.pterodactylus.sone.database.PostBuilder; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.util.logging.Logging; import freenet.keys.FreenetURI; +import com.google.common.base.Optional; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; @@ -54,6 +58,9 @@ public class DefaultSone implements Sone { /** The logger. */ private static final Logger logger = Logging.getLogger(DefaultSone.class); + /** The database. */ + private final Database database; + /** The ID of this Sone. */ private final String id; @@ -104,7 +111,7 @@ public class DefaultSone implements Sone { private final Set likedReplyIds = new CopyOnWriteArraySet(); /** The root album containing all albums. */ - private final Album rootAlbum = new DefaultAlbum(this, null); + private final Album rootAlbum; /** Sone-specific options. */ private Options options = new Options(); @@ -117,9 +124,11 @@ public class DefaultSone implements Sone { * @param local * {@code true} if the Sone is a local Sone, {@code false} otherwise */ - public DefaultSone(String id, boolean local) { + public DefaultSone(Database database, String id, boolean local) { + this.database = database; this.id = id; this.local = local; + rootAlbum = new DefaultAlbumBuilder(database, this, null).build(); } // @@ -664,6 +673,22 @@ public class DefaultSone implements Sone { this.options = options; } + @Override + public AlbumBuilder newAlbumBuilder() { + return new DefaultAlbumBuilder(database, this, rootAlbum.getId()); + } + + public PostBuilder newPostBuilder() { + return new DefaultPostBuilder(database, getId()) { + @Override + public Post build(Optional postCreated) { + Post post = super.build(postCreated); + database.storePost(post); + return post; + } + }; + } + // // FINGERPRINTABLE METHODS //