X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FFollowSonePage.kt;h=cf5bcee46bba83d4bd686b036b8e3f21ff55316d;hb=74cbe983cd38da24847e6247ac595cb70d8e115b;hp=75ce7f80ab94b58c4557c85b6cd039c2e1700994;hpb=ec655d61682a70063c1cf540fe3e41613aaf71a5;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt index 75ce7f8..cf5bcee 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.pages +import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.isPOST import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest @@ -10,22 +11,19 @@ import net.pterodactylus.util.template.TemplateContext * This page lets the user follow another Sone. */ class FollowSonePage(template: Template, webInterface: WebInterface): - SoneTemplatePage("followSone.html", template, "Page.FollowSone.Title", webInterface, true) { + LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.isPOST) { - request.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+")) + override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) { + if (freenetRequest.isPOST) { + freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+")) .map { it to webInterface.core.getSone(it) } - .filter { it.second.isPresent } - .map { it.first to it.second.get() } + .filterNot { it.second == null } .forEach { sone -> - webInterface.core.followSone(request.currentSone, sone.first) + webInterface.core.followSone(currentSone, sone.first) webInterface.core.markSoneKnown(sone.second) } - throw RedirectException(request.httpRequest.getPartAsStringFailsafe("returnPage", 256)) + throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) } } - private val FreenetRequest.currentSone get() = sessionProvider.getCurrentSone(toadletContext) - }