X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=4bf8a8a1a054d284512e76cfa6da64bc0d9037a7;hp=11095374d52a00a5dae71776bf64ff17c4ef9f14;hb=90d8e2eacb9888735865d8f890d105885959ca65;hpb=9f9834453e9555175e4771932d9521209bd7188c diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 1109537..4bf8a8a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -17,7 +17,6 @@ package net.pterodactylus.sone.core; -import static com.google.common.base.Optional.absent; import static com.google.common.base.Optional.of; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -27,7 +26,6 @@ import static net.pterodactylus.sone.data.Identified.GET_ID; import static net.pterodactylus.sone.data.Sone.LOCAL_SONE_FILTER; import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI; -import java.net.MalformedURLException; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -97,8 +95,7 @@ import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.util.thread.NamedThreadFactory; -import freenet.keys.FreenetURI; - +import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -330,6 +327,11 @@ public class Core extends AbstractService implements SoneProvider { } @Override + public Function> getSone() { + return database.getSone(); + } + + @Override public Optional getSone(String id) { synchronized (sones) { return Optional.fromNullable(sones.get(id)); @@ -411,40 +413,6 @@ public class Core extends AbstractService implements SoneProvider { } /** - * Returns all Sones that have liked the given post. - * - * @param post - * The post to get the liking Sones for - * @return The Sones that like the given post - */ - public Set getLikes(Post post) { - Set sones = new HashSet(); - for (Sone sone : getSones()) { - if (sone.getLikedPostIds().contains(post.getId())) { - sones.add(sone); - } - } - return sones; - } - - /** - * Returns all Sones that have liked the given reply. - * - * @param reply - * The reply to get the liking Sones for - * @return The Sones that like the given reply - */ - public Set getLikes(PostReply reply) { - Set sones = new HashSet(); - for (Sone sone : getSones()) { - if (sone.getLikedReplyIds().contains(reply.getId())) { - sones.add(sone); - } - } - return sones; - } - - /** * Returns whether the given post is bookmarked. * * @param post @@ -559,9 +527,8 @@ public class Core extends AbstractService implements SoneProvider { logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity)); synchronized (sones) { final Sone sone; - sone = database.newSoneBuilder().by(ownIdentity.getId()).local().build(Optional.absent()); + sone = database.newSoneBuilder().by(ownIdentity.getId()).local().using(new Client("Sone", SonePlugin.VERSION.toString())).build(Optional.absent()); sone.modify().setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0)).update(); - sone.setClient(new Client("Sone", SonePlugin.VERSION.toString())); sone.setKnown(true); /* TODO - load posts ’n stuff */ sones.put(ownIdentity.getId(), sone); @@ -617,7 +584,7 @@ public class Core extends AbstractService implements SoneProvider { return existingSone.get(); } boolean newSone = !existingSone.isPresent(); - final Sone sone = newSone ? database.newSoneBuilder().by(identity.getId()).build(Optional.absent()) : existingSone.get(); + final Sone sone = newSone ? database.newSoneBuilder().by(identity.getId()).using(new Client("Sone", SonePlugin.VERSION.toString())).build(Optional.absent()) : existingSone.get(); sone.modify().setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0)).update(); if (newSone) { synchronized (knownSones) { @@ -966,7 +933,7 @@ public class Core extends AbstractService implements SoneProvider { break; } String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue(""); - profile.addField(fieldName).setValue(fieldValue); + profile.setField(profile.addField(fieldName), fieldValue); } /* load posts. */ @@ -1095,7 +1062,7 @@ public class Core extends AbstractService implements SoneProvider { /* load avatar. */ String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null); if (avatarId != null) { - profile.setAvatar(getImage(avatarId).orNull()); + profile.setAvatar(getImage(avatarId).transform(GET_ID)); } /* load options. */ @@ -1679,6 +1646,7 @@ public class Core extends AbstractService implements SoneProvider { OwnIdentity ownIdentity = ownIdentityAddedEvent.ownIdentity(); logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity)); if (ownIdentity.hasContext("Sone")) { + database.storeIdentity(ownIdentity); addLocalSone(ownIdentity); } } @@ -1707,6 +1675,7 @@ public class Core extends AbstractService implements SoneProvider { Identity identity = identityAddedEvent.identity(); logger.log(Level.FINEST, String.format("Adding Identity: %s", identity)); trustedIdentities.put(identityAddedEvent.ownIdentity(), identity); + database.storeIdentity(identity); addRemoteSone(identity); } @@ -1719,6 +1688,7 @@ public class Core extends AbstractService implements SoneProvider { @Subscribe public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) { final Identity identity = identityUpdatedEvent.identity(); + database.storeIdentity(identity); soneDownloaders.execute(new Runnable() { @Override