1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.utils.isPOST
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
10 * This page lets the user follow another Sone.
12 class FollowSonePage(template: Template, webInterface: WebInterface):
13 SoneTemplatePage("followSone.html", template, "Page.FollowSone.Title", webInterface, true) {
15 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
16 if (freenetRequest.isPOST) {
17 freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+"))
18 .map { it to webInterface.core.getSone(it) }
19 .filterNot { it.second == null }
21 webInterface.core.followSone(freenetRequest.currentSone, sone.first)
22 webInterface.core.markSoneKnown(sone.second)
24 throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
28 private val FreenetRequest.currentSone get() = sessionProvider.getCurrentSone(toadletContext)