From: David ‘Bombe’ Roden Date: Sat, 23 Oct 2010 11:24:38 +0000 (+0200) Subject: Add like functionality to replies. X-Git-Tag: 0.1-RC1~60 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=63e85ddb7cebbb91f7be41640edb6104bd74650a;p=Sone.git Add like functionality to replies. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java new file mode 100644 index 0000000..d5fd7e4 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java @@ -0,0 +1,54 @@ +/* + * Sone - ReplyAccessor.java - Copyright © 2010 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.template; + +import net.pterodactylus.sone.core.Core; +import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; +import net.pterodactylus.util.template.ReflectionAccessor; + +/** + * TODO + * + * @author David ‘Bombe’ Roden + */ +public class ReplyAccessor extends ReflectionAccessor { + + private final Core core; + + public ReplyAccessor(Core core) { + this.core = core; + } + + /** + * {@inheritDoc} + */ + @Override + public Object get(DataProvider dataProvider, Object object, String member) { + Reply reply = (Reply) object; + if ("likes".equals(member)) { + return core.getLikes(reply); + } else if (member.equals("liked")) { + Sone currentSone = (Sone) dataProvider.getData("currentSone"); + return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId())); + } + return super.get(dataProvider, object, member); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index d809580..78a03b5 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -30,11 +30,13 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.L10nFilter; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.template.GetPagePlugin; import net.pterodactylus.sone.template.PostAccessor; +import net.pterodactylus.sone.template.ReplyAccessor; import net.pterodactylus.sone.template.RequestChangeFilter; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.template.SubstringFilter; @@ -177,6 +179,7 @@ public class WebInterface extends AbstractService { templateFactory.addAccessor(Object.class, new ReflectionAccessor()); templateFactory.addAccessor(Sone.class, new SoneAccessor(core())); templateFactory.addAccessor(Post.class, new PostAccessor(core())); + templateFactory.addAccessor(Reply.class, new ReplyAccessor(core())); templateFactory.addFilter("date", new DateFilter()); templateFactory.addFilter("l10n", new L10nFilter(l10n())); templateFactory.addFilter("substring", new SubstringFilter()); diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index d212c39..8b4911d 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -40,6 +40,23 @@
<% reply.time|date format="MMM d, yyyy, HH:mm:ss">
+
⬆
+ <%ifnull ! currentSone> +
+ + + + + +
+
+ + + + + +
+ <%/if> <%if reply.sone.current>