X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSoneAccessor.java;h=b072dc9e6ee94156d5962ebceea16dfea611bd89;hp=eac8a93f1b6ef9bd38b791785265f885eeaa9db4;hb=HEAD;hpb=50ce65f69e49ed10abeedaeb6615ffb37a0c0772 diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index eac8a93..b072dc9 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -1,5 +1,5 @@ /* - * Sone - SoneAccessor.java - Copyright © 2010–2012 David Roden + * Sone - SoneAccessor.java - Copyright © 2010–2020 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +17,8 @@ package net.pterodactylus.sone.template; +import static java.util.logging.Logger.getLogger; + import java.util.logging.Level; import java.util.logging.Logger; @@ -24,10 +26,10 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.data.SoneKt; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.freenet.wot.Trust; -import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage; -import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.sone.text.TimeTextConverter; import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; @@ -46,16 +48,15 @@ import net.pterodactylus.util.template.TemplateContext; *
Will return {@code true} if the sone in question is the currently logged * in Sone.
* - * - * @author David ‘Bombe’ Roden */ public class SoneAccessor extends ReflectionAccessor { /** The logger. */ - private static final Logger logger = Logging.getLogger(SoneAccessor.class); + private static final Logger logger = getLogger(SoneAccessor.class.getName()); /** The core. */ private final Core core; + private final TimeTextConverter timeTextConverter; /** * Creates a new Sone accessor. @@ -63,8 +64,9 @@ public class SoneAccessor extends ReflectionAccessor { * @param core * The Sone core */ - public SoneAccessor(Core core) { + public SoneAccessor(Core core, TimeTextConverter timeTextConverter) { this.core = core; + this.timeTextConverter = timeTextConverter; } /** @@ -75,8 +77,6 @@ public class SoneAccessor extends ReflectionAccessor { Sone sone = (Sone) object; if (member.equals("niceName")) { return getNiceName(sone); - } else if (member.equals("local")) { - return core.isLocalSone(sone); } else if (member.equals("friend")) { Sone currentSone = (Sone) templateContext.get("currentSone"); return (currentSone != null) && currentSone.hasFriend(sone.getId()); @@ -100,18 +100,22 @@ public class SoneAccessor extends ReflectionAccessor { } else if (member.equals("locked")) { return core.isLocked(sone); } else if (member.equals("lastUpdatedText")) { - return GetTimesAjaxPage.getTime((WebInterface) templateContext.get("webInterface"), sone.getTime()); + return timeTextConverter.getTimeText(sone.getTime()).getL10nText(); } else if (member.equals("trust")) { Sone currentSone = (Sone) templateContext.get("currentSone"); if (currentSone == null) { return null; } - Trust trust = core.getTrust(currentSone, sone); + Trust trust = sone.getIdentity().getTrust((OwnIdentity) currentSone.getIdentity()); logger.log(Level.FINEST, String.format("Trust for %s by %s: %s", sone, currentSone, trust)); if (trust == null) { return new Trust(null, null, null); } return trust; + } else if (member.equals("allImages")) { + return SoneKt.getAllImages(sone); + } else if (member.equals("albums")) { + return sone.getRootAlbum().getAlbums(); } return super.get(templateContext, object, member); }