Change a couple of method argument names
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / FollowSonePage.kt
1 package net.pterodactylus.sone.web.pages
2
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
8
9 /**
10  * This page lets the user follow another Sone.
11  */
12 class FollowSonePage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("followSone.html", template, "Page.FollowSone.Title", webInterface, true) {
14
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                                         .filter { it.second.isPresent }
20                                         .map { it.first to it.second.get() }
21                                         .forEach { sone ->
22                                                 webInterface.core.followSone(freenetRequest.currentSone, sone.first)
23                                                 webInterface.core.markSoneKnown(sone.second)
24                                         }
25                         throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
26                 }
27         }
28
29         private val FreenetRequest.currentSone get() = sessionProvider.getCurrentSone(toadletContext)
30
31 }