Return local Sones from core and web interface.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 02a5dd5..e245b6a 100644 (file)
@@ -64,6 +64,7 @@ import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Profile;
@@ -381,7 +382,7 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(ToadletContext toadletContext) {
+       public Optional<LocalSone> getCurrentSone(ToadletContext toadletContext) {
                return getCurrentSone(toadletContext, true);
        }
 
@@ -396,10 +397,10 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(ToadletContext toadletContext, boolean createSession) {
-               Collection<Sone> localSones = getCore().getLocalSones();
+       public Optional<LocalSone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
+               Collection<LocalSone> localSones = getCore().getLocalSones();
                if (localSones.size() == 1) {
-                       return localSones.iterator().next();
+                       return Optional.of(localSones.iterator().next());
                }
                return getCurrentSone(getCurrentSession(toadletContext, createSession));
        }
@@ -412,13 +413,13 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Sone getCurrentSone(Optional<Session> session) {
+       public Optional<LocalSone> getCurrentSone(Optional<Session> session) {
                if (!session.isPresent()) {
-                       return null;
+                       return Optional.absent();
                }
                String soneId = (String) session.get().getAttribute("Sone.CurrentSone");
                if (soneId == null) {
-                       return null;
+                       return Optional.absent();
                }
                return getCore().getLocalSone(soneId);
        }