import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface)
: SoneTemplatePage("bookmark.html", webInterface, template, "Page.Bookmark.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
- val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)
- webInterface.core.getPost(postId)?.let {
- webInterface.core.bookmarkPost(it)
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)
+ soneRequest.core.getPost(postId)?.let {
+ soneRequest.core.bookmarkPost(it)
}
throw RedirectException(returnPage)
}
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface) :
SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- webInterface.core.bookmarkedPosts.let { posts ->
- val pagination = posts.filter(Post::isLoaded).sortedByDescending { it.time }.paginate(webInterface.core.preferences.postsPerPage)
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ soneRequest.core.bookmarkedPosts.let { posts ->
+ val pagination = posts.filter(Post::isLoaded).sortedByDescending { it.time }.paginate(soneRequest.core.preferences.postsPerPage)
templateContext["pagination"] = pagination
templateContext["posts"] = pagination.items
templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val name = freenetRequest.httpRequest.getPartAsStringFailsafe("name", 64).trim()
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val name = soneRequest.httpRequest.getPartAsStringFailsafe("name", 64).trim()
if (name.isEmpty()) {
templateContext["nameMissing"] = true
return
}
- val description = freenetRequest.httpRequest.getPartAsStringFailsafe("description", 256).trim()
- val parentId = freenetRequest.httpRequest.getPartAsStringFailsafe("parent", 36)
- val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId)
- val album = webInterface.core.createAlbum(currentSone, parent)
+ val description = soneRequest.httpRequest.getPartAsStringFailsafe("description", 256).trim()
+ val parentId = soneRequest.httpRequest.getPartAsStringFailsafe("parent", 36)
+ val parent = if (parentId == "") currentSone.rootAlbum else soneRequest.core.getAlbum(parentId)
+ val album = soneRequest.core.createAlbum(currentSone, parent)
try {
album.modify().apply {
setTitle(name)
- setDescription(TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), description))
+ setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), description))
}.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
throw RedirectException("emptyAlbumTitle.html")
}
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.id}")
}
}
import net.pterodactylus.sone.utils.asOptional
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
templateContext["returnPage"] = returnPage
- if (freenetRequest.isPOST) {
- val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
+ if (soneRequest.isPOST) {
+ val text = soneRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim()
if (text == "") {
templateContext["errorTextEmpty"] = true
return
}
- val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
- val recipient = webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
- webInterface.core.createPost(sender, recipient.asOptional(), TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
+ val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
+ val recipient = soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
+ soneRequest.core.createPost(sender, recipient.asOptional(), TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
}
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
- val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
- if (freenetRequest.isPOST) {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
+ val text = soneRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
+ if (soneRequest.isPOST) {
if (text == "") {
templateContext["errorTextEmpty"] = true
return
}
- val post = webInterface.core.getPost(postId) ?: throw RedirectException("noPermission.html")
- val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
- webInterface.core.createReply(sender, post, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
+ val post = soneRequest.core.getPost(postId) ?: throw RedirectException("noPermission.html")
+ val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
+ soneRequest.core.createReply(sender, post, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import java.util.logging.Level
private val logger = Logger.getLogger(CreateSonePage::class.java.name)
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
- templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() }
- if (freenetRequest.isPOST) {
- val identity = freenetRequest.httpRequest.getPartAsStringFailsafe("identity", 43)
- webInterface.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity ->
- val sone = webInterface.core.createSone(ownIdentity)
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
+ templateContext["identitiesWithoutSone"] = soneRequest.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}".toLowerCase() }
+ if (soneRequest.isPOST) {
+ val identity = soneRequest.httpRequest.getPartAsStringFailsafe("identity", 43)
+ soneRequest.core.identityManager.allOwnIdentities.firstOrNull { it.id == identity }?.let { ownIdentity ->
+ val sone = soneRequest.core.createSone(ownIdentity)
if (sone == null) {
logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity")
}
- setCurrentSone(freenetRequest.toadletContext, sone)
+ setCurrentSone(soneRequest.toadletContext, sone)
throw RedirectException("index.html")
}
templateContext["errorNoIdentity"] = true
}
}
- override fun isEnabled(toadletContext: ToadletContext) =
- if (webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess) {
+ override fun isEnabled(soneRequest: SoneRequest) =
+ if (soneRequest.core.preferences.requireFullAccess && !soneRequest.toadletContext.isAllowedFullAccess) {
false
} else {
- (getCurrentSone(toadletContext) == null) || (webInterface.core.localSones.size == 1)
+ (getCurrentSone(soneRequest.toadletContext) == null) || (soneRequest.core.localSones.size == 1)
}
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
if (!album.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
throw RedirectException("imageBrowser.html?album=${album.id}")
}
- webInterface.core.deleteAlbum(album)
+ soneRequest.core.deleteAlbum(album)
throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
}
- val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getParam("album"))
+ val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getParam("album"))
templateContext["album"] = album ?: throw RedirectException("invalid.html")
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
+ if (soneRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException("imageBrowser.html?image=${image.id}")
}
- webInterface.core.deleteImage(image)
+ soneRequest.core.deleteImage(image)
throw RedirectException("imageBrowser.html?album=${image.album.id}")
}
- val image = webInterface.core.getImage(freenetRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html")
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html")
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
if (!post.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
- webInterface.core.deletePost(post)
+ if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
+ soneRequest.core.deletePost(post)
throw RedirectException(returnPage)
- } else if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
+ } else if (soneRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException(returnPage)
}
templateContext["post"] = post
templateContext["returnPage"] = returnPage
return
}
- templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html")
- templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")
+ templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html")
+ templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage")
}
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
currentSone.profile = currentSone.profile.apply { removeField(field) }
}
throw RedirectException("editProfile.html#profile-fields")
}
- val field = currentSone.profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
templateContext["field"] = field
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val replyId = freenetRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
- val reply = webInterface.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val replyId = soneRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
+ val reply = soneRequest.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
if (!reply.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
- if (freenetRequest.httpRequest.isPartSet("confirmDelete")) {
- webInterface.core.deleteReply(reply)
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
+ soneRequest.core.deleteReply(reply)
throw RedirectException(returnPage)
}
- if (freenetRequest.httpRequest.isPartSet("abortDelete")) {
+ if (soneRequest.httpRequest.isPartSet("abortDelete")) {
throw RedirectException(returnPage)
}
templateContext["reply"] = replyId
templateContext["returnPage"] = returnPage
return
}
- templateContext["reply"] = freenetRequest.httpRequest.getParam("reply")
- templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage")
+ templateContext["reply"] = soneRequest.httpRequest.getParam("reply")
+ templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage")
}
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- if (freenetRequest.httpRequest.isPartSet("deleteSone")) {
- webInterface.core.deleteSone(currentSone)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ if (soneRequest.httpRequest.isPartSet("deleteSone")) {
+ soneRequest.core.deleteSone(currentSone)
}
throw RedirectException("index.html")
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("dismissNotification.html", webInterface, template, "Page.DismissNotification.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
- val notificationId = freenetRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
- webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+ val notificationId = soneRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
+ soneRequest.webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
throw RedirectException(returnPage)
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- webInterface.core.getSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sone", 44))
- ?.run { webInterface.core.distrustSone(currentSone, this) }
- throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("sone", 44))
+ ?.run { soneRequest.core.distrustSone(currentSone, this) }
+ throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val album = webInterface.core.getAlbum(freenetRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
album.parent?.moveAlbumUp(album)
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
album.parent?.moveAlbumDown(album)
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
} else {
try {
album.modify()
- .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
- .setDescription(freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
+ .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
+ .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
throw RedirectException("emptyAlbumTitle.html")
}
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("imageBrowser.html?album=${album.id}")
}
}
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val image = webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
if (!image.sone.isLocal) {
throw RedirectException("noPermission.html")
}
- freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
+ soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
image.album.moveImageUp(image)
- webInterface.core.touchConfiguration()
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
+ soneRequest.core.touchConfiguration()
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
image.album.moveImageDown(image)
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
} else {
try {
image.modify()
- .setTitle(freenetRequest.httpRequest.getPartAsStringFailsafe("title", 100))
- .setDescription(TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), freenetRequest.httpRequest.getPartAsStringFailsafe("description", 1024)))
+ .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
+ .setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), soneRequest.httpRequest.getPartAsStringFailsafe("description", 1024)))
.update()
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
} catch (e: ImageTitleMustNotBeEmpty) {
throw RedirectException("emptyImageTitle.html")
}
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
currentSone.profile.let { profile ->
- if (freenetRequest.isPOST) {
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
+ if (soneRequest.isPOST) {
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
throw RedirectException("editProfile.html#profile-fields")
}
- val field = profile.getFieldById(freenetRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
- freenetRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
+ val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
try {
if (name != field.name) {
field.name = name
}
}
}
- templateContext["field"] = profile.getFieldById(freenetRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
}
}
import net.pterodactylus.sone.text.TextFilter
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
currentSone.profile.let { profile ->
templateContext["firstName"] = profile.firstName
templateContext["middleName"] = profile.middleName
templateContext["birthYear"] = profile.birthYear
templateContext["avatarId"] = profile.avatar
templateContext["fields"] = profile.fields
- if (freenetRequest.isPOST) {
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("save-profile", 4) == "true") {
- profile.firstName = freenetRequest.httpRequest.getPartAsStringFailsafe("first-name", 256).trim()
- profile.middleName = freenetRequest.httpRequest.getPartAsStringFailsafe("middle-name", 256).trim()
- profile.lastName = freenetRequest.httpRequest.getPartAsStringFailsafe("last-name", 256).trim()
- profile.birthDay = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-day", 256).trim().toIntOrNull()
- profile.birthMonth = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-month", 256).trim().toIntOrNull()
- profile.birthYear = freenetRequest.httpRequest.getPartAsStringFailsafe("birth-year", 256).trim().toIntOrNull()
- profile.setAvatar(webInterface.core.getImage(freenetRequest.httpRequest.getPartAsStringFailsafe("avatarId", 256).trim(), false))
+ if (soneRequest.isPOST) {
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("save-profile", 4) == "true") {
+ profile.firstName = soneRequest.httpRequest.getPartAsStringFailsafe("first-name", 256).trim()
+ profile.middleName = soneRequest.httpRequest.getPartAsStringFailsafe("middle-name", 256).trim()
+ profile.lastName = soneRequest.httpRequest.getPartAsStringFailsafe("last-name", 256).trim()
+ profile.birthDay = soneRequest.httpRequest.getPartAsStringFailsafe("birth-day", 256).trim().toIntOrNull()
+ profile.birthMonth = soneRequest.httpRequest.getPartAsStringFailsafe("birth-month", 256).trim().toIntOrNull()
+ profile.birthYear = soneRequest.httpRequest.getPartAsStringFailsafe("birth-year", 256).trim().toIntOrNull()
+ profile.setAvatar(soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("avatarId", 256).trim(), false))
profile.fields.forEach { field ->
- field.value = TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), freenetRequest.httpRequest.getPartAsStringFailsafe("field-${field.id}", 400).trim())
+ field.value = TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), soneRequest.httpRequest.getPartAsStringFailsafe("field-${field.id}", 400).trim())
}
currentSone.profile = profile
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("editProfile.html")
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
- val fieldName = freenetRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
+ val fieldName = soneRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
try {
profile.addField(fieldName)
currentSone.profile = profile
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("editProfile.html#profile-fields")
} catch (e: DuplicateField) {
templateContext["fieldName"] = fieldName
templateContext["duplicateFieldName"] = true
}
} else profile.fields.forEach { field ->
- if (freenetRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
+ if (soneRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
throw RedirectException("deleteProfileField.html?field=${field.id}")
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
throw RedirectException("editProfileField.html?field=${field.id}")
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
profile.moveFieldDown(field)
currentSone.profile = profile
throw RedirectException("editProfile.html#profile-fields")
- } else if (freenetRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
+ } else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
profile.moveFieldUp(field)
currentSone.profile = profile
throw RedirectException("editProfile.html#profile-fields")
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
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface) {
- 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) }
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.httpRequest.getPartAsStringFailsafe("sone", 1200).split(Regex("[ ,]+"))
+ .map { it to soneRequest.core.getSone(it) }
.filterNot { it.second == null }
.forEach { sone ->
- webInterface.core.followSone(currentSone, sone.first)
- webInterface.core.markSoneKnown(sone.second)
+ soneRequest.core.followSone(currentSone, sone.first)
+ soneRequest.core.markSoneKnown(sone.second)
}
- throw RedirectException(freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import java.net.URI
class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if ("album" in freenetRequest.parameters) {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if ("album" in soneRequest.parameters) {
templateContext["albumRequested"] = true
- templateContext["album"] = webInterface.core.getAlbum(freenetRequest.parameters["album"]!!)
- templateContext["page"] = freenetRequest.parameters["page"]
- } else if ("image" in freenetRequest.parameters) {
+ templateContext["album"] = soneRequest.core.getAlbum(soneRequest.parameters["album"]!!)
+ templateContext["page"] = soneRequest.parameters["page"]
+ } else if ("image" in soneRequest.parameters) {
templateContext["imageRequested"] = true
- templateContext["image"] = webInterface.core.getImage(freenetRequest.parameters["image"])
- } else if (freenetRequest.parameters["mode"] == "gallery") {
+ templateContext["image"] = soneRequest.core.getImage(soneRequest.parameters["image"])
+ } else if (soneRequest.parameters["mode"] == "gallery") {
templateContext["galleryRequested"] = true
- webInterface.core.sones
+ soneRequest.core.sones
.map(Sone::getRootAlbum)
.flatMap(Album::getAlbums)
.flatMap { Album.FLATTENER.apply(it)!! }
.filterNot(Album::isEmpty)
.sortedBy(Album::getTitle)
.also { albums ->
- albums.paginate(webInterface.core.preferences.imagesPerPage)
- .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0)
+ albums.paginate(soneRequest.core.preferences.imagesPerPage)
+ .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
.also { pagination ->
templateContext["albumPagination"] = pagination
templateContext["albums"] = pagination.items
}
} else {
templateContext["soneRequested"] = true
- templateContext["sone"] = webInterface.core.getSone(freenetRequest.httpRequest.getParam("sone")) ?: currentSone
+ templateContext["sone"] = soneRequest.core.getSone(soneRequest.httpRequest.getParam("sone")) ?: currentSone
}
}
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, private val postVisibilityFilter: PostVisibilityFilter) :
LoggedInPage("index.html", template, "Page.Index.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
(currentSone.posts +
currentSone.friends
- .mapNotNull(webInterface.core::getSone)
+ .mapNotNull(soneRequest.core::getSone)
.flatMap { it.posts } +
- webInterface.core.getDirectedPosts(currentSone.id)
+ soneRequest.core.getDirectedPosts(currentSone.id)
).distinct()
.filter { postVisibilityFilter.isVisible(currentSone).apply(it) }
.sortedByDescending { it.time }
.let { posts ->
- posts.paginate(webInterface.core.preferences.postsPerPage)
- .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0)
+ posts.paginate(soneRequest.core.preferences.postsPerPage)
+ .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
.let { pagination ->
templateContext["pagination"] = pagination
templateContext["posts"] = pagination.items
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("knownSones.html", webInterface, template, "Page.KnownSones.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
- webInterface.core.sones.asSequence()
- .filterNot { freenetRequest.parameters["filter"] == "followed" && currentSone != null && !currentSone.hasFriend(it.id) }
- .filterNot { freenetRequest.parameters["filter"] == "not-followed" && currentSone != null && currentSone.hasFriend(it.id) }
- .filterNot { freenetRequest.parameters["filter"] == "new" && it.isKnown }
- .filterNot { freenetRequest.parameters["filter"] == "not-new" && !it.isKnown }
- .filterNot { freenetRequest.parameters["filter"] == "own" && !it.isLocal }
- .filterNot { freenetRequest.parameters["filter"] == "not-own" && it.isLocal }
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ getCurrentSone(soneRequest.toadletContext).let { currentSone ->
+ soneRequest.core.sones.asSequence()
+ .filterNot { soneRequest.parameters["filter"] == "followed" && currentSone != null && !currentSone.hasFriend(it.id) }
+ .filterNot { soneRequest.parameters["filter"] == "not-followed" && currentSone != null && currentSone.hasFriend(it.id) }
+ .filterNot { soneRequest.parameters["filter"] == "new" && it.isKnown }
+ .filterNot { soneRequest.parameters["filter"] == "not-new" && !it.isKnown }
+ .filterNot { soneRequest.parameters["filter"] == "own" && !it.isLocal }
+ .filterNot { soneRequest.parameters["filter"] == "not-own" && it.isLocal }
.sortedWith(
- when (freenetRequest.parameters["sort"]) {
+ when (soneRequest.parameters["sort"]) {
"images" -> Sone.IMAGE_COUNT_COMPARATOR
"name" -> Sone.NICE_NAME_COMPARATOR.reversed()
"posts" -> Sone.POST_COUNT_COMPARATOR
else -> Sone.LAST_ACTIVITY_COMPARATOR
}.let { comparator ->
- when (freenetRequest.parameters["order"]) {
+ when (soneRequest.parameters["order"]) {
"asc" -> comparator.reversed()
else -> comparator
}
}
).paginate(25)
- .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0)
+ .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
.let { pagination ->
templateContext["pagination"] = pagination
templateContext["knownSones"] = pagination.items
}
- templateContext["sort"] = freenetRequest.parameters["sort"].let { sort -> if (sort in listOf("images", "name", "posts")) sort else "activity" }
- templateContext["order"] = freenetRequest.parameters["order"].let { order -> if (order == "asc") "asc" else "desc" }
- templateContext["filter"] = freenetRequest.parameters["filter"]
+ templateContext["sort"] = soneRequest.parameters["sort"].let { sort -> if (sort in listOf("images", "name", "posts")) sort else "activity" }
+ templateContext["order"] = soneRequest.parameters["order"].let { order -> if (order == "asc") "asc" else "desc" }
+ templateContext["filter"] = soneRequest.parameters["filter"]
}
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class LikePage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("like.html", template, "Page.Like.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- freenetRequest.parameters["type", 16]?.also { type ->
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.parameters["type", 16]?.also { type ->
when (type) {
- "post" -> currentSone.addLikedPostId(freenetRequest.parameters["post", 36]!!)
- "reply" -> currentSone.addLikedReplyId(freenetRequest.parameters["reply", 36]!!)
+ "post" -> currentSone.addLikedPostId(soneRequest.parameters["post", 36]!!)
+ "reply" -> currentSone.addLikedReplyId(soneRequest.parameters["reply", 36]!!)
}
}
- throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
+ throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
}
}
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("lockSone.html", webInterface, template, "Page.LockSone.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- freenetRequest.parameters["returnPage", 256]!!.let { returnPage ->
- freenetRequest.parameters["sone", 44]!!
- .let { webInterface.core.getLocalSone(it) }
- ?.let { webInterface.core.lockSone(it) }
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ soneRequest.parameters["returnPage", 256]!!.let { returnPage ->
+ soneRequest.parameters["sone", 44]!!
+ .let { soneRequest.core.getLocalSone(it) }
+ ?.let { soneRequest.core.lockSone(it) }
throw RedirectException(returnPage)
}
}
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface) :
SoneTemplatePage(path, webInterface, template, pageTitleKey, true) {
- final override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- handleRequest(freenetRequest, getCurrentSone(freenetRequest.toadletContext, false)!!, templateContext)
+ final override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ handleRequest(soneRequest, getCurrentSone(soneRequest.toadletContext, false)!!, templateContext)
}
- protected abstract fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext)
+ protected abstract fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext)
}
import net.pterodactylus.sone.utils.emptyToNull
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class LoginPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("login.html", webInterface, template, "Page.Login.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val soneId = freenetRequest.httpRequest.getPartAsStringFailsafe("sone-id", 43)
- webInterface.core.getLocalSone(soneId)?.let { sone ->
- setCurrentSone(freenetRequest.toadletContext, sone)
- val target = freenetRequest.httpRequest.getParam("target").emptyToNull ?: "index.html"
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val soneId = soneRequest.httpRequest.getPartAsStringFailsafe("sone-id", 43)
+ soneRequest.core.getLocalSone(soneId)?.let { sone ->
+ setCurrentSone(soneRequest.toadletContext, sone)
+ val target = soneRequest.httpRequest.getParam("target").emptyToNull ?: "index.html"
throw RedirectException(target)
}
}
- templateContext["sones"] = webInterface.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
- templateContext["identitiesWithoutSone"] = webInterface.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}" }
+ templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
+ templateContext["identitiesWithoutSone"] = soneRequest.core.identityManager.allOwnIdentities.filterNot { "Sone" in it.contexts }.sortedBy { "${it.nickname}@${it.id}" }
}
override fun getRedirectTarget(freenetRequest: FreenetRequest) =
getCurrentSone(freenetRequest.toadletContext)?.let { "index.html" }
- override fun isEnabled(toadletContext: ToadletContext) = when {
- webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess -> false
- else -> getCurrentSone(toadletContext, false) == null
+ override fun isEnabled(soneRequest: SoneRequest) = when {
+ soneRequest.core.preferences.requireFullAccess && !soneRequest.toadletContext.isAllowedFullAccess -> false
+ else -> getCurrentSone(soneRequest.toadletContext, false) == null
}
}
import freenet.clients.http.ToadletContext
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- setCurrentSone(freenetRequest.toadletContext, null)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ setCurrentSone(soneRequest.toadletContext, null)
throw RedirectException("index.html")
}
- override fun isEnabled(toadletContext: ToadletContext): Boolean =
- if (webInterface.core.preferences.requireFullAccess && !toadletContext.isAllowedFullAccess) {
+ override fun isEnabled(soneRequest: SoneRequest): Boolean =
+ if (soneRequest.core.preferences.requireFullAccess && !soneRequest.toadletContext.isAllowedFullAccess) {
false
} else
- getCurrentSone(toadletContext) != null && webInterface.core.localSones.size != 1
+ getCurrentSone(soneRequest.toadletContext) != null && soneRequest.core.localSones.size != 1
}
class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("markAsKnown.html", webInterface, template, "Page.MarkAsKnown.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- val ids = freenetRequest.parameters["id", 65536]!!.split(" ")
- when (freenetRequest.parameters["type", 5]) {
- "sone" -> ids.mapNotNull(webInterface.core::getSone).forEach(webInterface.core::markSoneKnown)
- "post" -> ids.mapNotNull(webInterface.core::getPost).forEach(webInterface.core::markPostKnown)
- "reply" -> ids.mapNotNull(webInterface.core::getPostReply).forEach(webInterface.core::markReplyKnown)
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ val ids = soneRequest.parameters["id", 65536]!!.split(" ")
+ when (soneRequest.parameters["type", 5]) {
+ "sone" -> ids.mapNotNull(soneRequest.core::getSone).forEach(soneRequest.core::markSoneKnown)
+ "post" -> ids.mapNotNull(soneRequest.core::getPost).forEach(soneRequest.core::markPostKnown)
+ "reply" -> ids.mapNotNull(soneRequest.core::getPostReply).forEach(soneRequest.core::markReplyKnown)
else -> throw RedirectException("invalid.html")
}
- throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
+ throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
}
}
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class NewPage @Inject constructor( template: Template, webInterface: WebInterface):
SoneTemplatePage("new.html", webInterface, template, "Page.New.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) =
- getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
- (webInterface.getNewPosts(currentSone) + webInterface.getNewReplies(currentSone).mapPresent { it.post })
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
+ getCurrentSone(soneRequest.toadletContext).let { currentSone ->
+ (soneRequest.webInterface.getNewPosts(currentSone) + soneRequest.webInterface.getNewReplies(currentSone).mapPresent { it.post })
.distinct()
.sortedByDescending { it.time }
.let { posts ->
- posts.paginate(webInterface.core.preferences.postsPerPage)
- .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0)
+ posts.paginate(soneRequest.core.preferences.postsPerPage)
+ .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
.let { pagination ->
templateContext["pagination"] = pagination
templateContext["posts"] = pagination.items
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("options.html", webInterface, template, "Page.Options.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
val fieldsWithErrors = mutableListOf<String>()
- getCurrentSone(freenetRequest.toadletContext)?.options?.let { options ->
- val autoFollow = "auto-follow" in freenetRequest.parameters
- val loadLinkedImages = freenetRequest.parameters["load-linked-images"].emptyToNull
- val showCustomAvatars = freenetRequest.parameters["show-custom-avatars"].emptyToNull
- val enableSoneInsertNotification = "enable-sone-insert-notifications" in freenetRequest.parameters
- val showNewSoneNotification = "show-notification-new-sones" in freenetRequest.parameters
- val showNewPostNotification = "show-notification-new-posts" in freenetRequest.parameters
- val showNewReplyNotification = "show-notification-new-replies" in freenetRequest.parameters
+ getCurrentSone(soneRequest.toadletContext)?.options?.let { options ->
+ val autoFollow = "auto-follow" in soneRequest.parameters
+ val loadLinkedImages = soneRequest.parameters["load-linked-images"].emptyToNull
+ val showCustomAvatars = soneRequest.parameters["show-custom-avatars"].emptyToNull
+ val enableSoneInsertNotification = "enable-sone-insert-notifications" in soneRequest.parameters
+ val showNewSoneNotification = "show-notification-new-sones" in soneRequest.parameters
+ val showNewPostNotification = "show-notification-new-posts" in soneRequest.parameters
+ val showNewReplyNotification = "show-notification-new-replies" in soneRequest.parameters
options.isAutoFollow = autoFollow
options.isSoneInsertNotificationEnabled = enableSoneInsertNotification
loadLinkedImages?.also { if (cantSetOption { options.loadLinkedImages = LoadExternalContent.valueOf(loadLinkedImages) }) fieldsWithErrors += "load-linked-images" }
showCustomAvatars?.also { if (cantSetOption { options.showCustomAvatars = LoadExternalContent.valueOf(showCustomAvatars) }) fieldsWithErrors += "show-custom-avatars" }
}
- val fullAccessRequired = "require-full-access" in freenetRequest.parameters
- val fcpInterfaceActive = "fcp-interface-active" in freenetRequest.parameters
+ val fullAccessRequired = "require-full-access" in soneRequest.parameters
+ val fcpInterfaceActive = "fcp-interface-active" in soneRequest.parameters
- webInterface.core.preferences.newRequireFullAccess = fullAccessRequired
- webInterface.core.preferences.newFcpInterfaceActive = fcpInterfaceActive
+ soneRequest.core.preferences.newRequireFullAccess = fullAccessRequired
+ soneRequest.core.preferences.newFcpInterfaceActive = fcpInterfaceActive
- val postsPerPage = freenetRequest.parameters["posts-per-page"]?.toIntOrNull()
- val charactersPerPost = freenetRequest.parameters["characters-per-post"]?.toIntOrNull()
- val postCutOffLength = freenetRequest.parameters["post-cut-off-length"]?.toIntOrNull()
- val imagesPerPage = freenetRequest.parameters["images-per-page"]?.toIntOrNull()
- val insertionDelay = freenetRequest.parameters["insertion-delay"]?.toIntOrNull()
- val fcpFullAccessRequired = freenetRequest.parameters["fcp-full-access-required"]?.toIntOrNull()
- val negativeTrust = freenetRequest.parameters["negative-trust"]?.toIntOrNull()
- val positiveTrust = freenetRequest.parameters["positive-trust"]?.toIntOrNull()
- val trustComment = freenetRequest.parameters["trust-comment"]?.emptyToNull
+ val postsPerPage = soneRequest.parameters["posts-per-page"]?.toIntOrNull()
+ val charactersPerPost = soneRequest.parameters["characters-per-post"]?.toIntOrNull()
+ val postCutOffLength = soneRequest.parameters["post-cut-off-length"]?.toIntOrNull()
+ val imagesPerPage = soneRequest.parameters["images-per-page"]?.toIntOrNull()
+ val insertionDelay = soneRequest.parameters["insertion-delay"]?.toIntOrNull()
+ val fcpFullAccessRequired = soneRequest.parameters["fcp-full-access-required"]?.toIntOrNull()
+ val negativeTrust = soneRequest.parameters["negative-trust"]?.toIntOrNull()
+ val positiveTrust = soneRequest.parameters["positive-trust"]?.toIntOrNull()
+ val trustComment = soneRequest.parameters["trust-comment"]?.emptyToNull
- if (cantSetOption { it.newPostsPerPage = postsPerPage }) fieldsWithErrors += "posts-per-page"
- if (cantSetOption { it.newCharactersPerPost = charactersPerPost }) fieldsWithErrors += "characters-per-post"
- if (cantSetOption { it.newPostCutOffLength = postCutOffLength }) fieldsWithErrors += "post-cut-off-length"
- if (cantSetOption { it.newImagesPerPage = imagesPerPage }) fieldsWithErrors += "images-per-page"
- if (cantSetOption { it.newInsertionDelay = insertionDelay }) fieldsWithErrors += "insertion-delay"
- fcpFullAccessRequired?.also { if (cantSetOption { it.newFcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" }
- if (cantSetOption { it.newNegativeTrust = negativeTrust }) fieldsWithErrors += "negative-trust"
- if (cantSetOption { it.newPositiveTrust = positiveTrust }) fieldsWithErrors += "positive-trust"
- if (cantSetOption { it.newTrustComment = trustComment }) fieldsWithErrors += "trust-comment"
+ if (cantSetOption { soneRequest.core.preferences.newPostsPerPage = postsPerPage }) fieldsWithErrors += "posts-per-page"
+ if (cantSetOption { soneRequest.core.preferences.newCharactersPerPost = charactersPerPost }) fieldsWithErrors += "characters-per-post"
+ if (cantSetOption { soneRequest.core.preferences.newPostCutOffLength = postCutOffLength }) fieldsWithErrors += "post-cut-off-length"
+ if (cantSetOption { soneRequest.core.preferences.newImagesPerPage = imagesPerPage }) fieldsWithErrors += "images-per-page"
+ if (cantSetOption { soneRequest.core.preferences.newInsertionDelay = insertionDelay }) fieldsWithErrors += "insertion-delay"
+ fcpFullAccessRequired?.also { if (cantSetOption { soneRequest.core.preferences.newFcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" }
+ if (cantSetOption { soneRequest.core.preferences.newNegativeTrust = negativeTrust }) fieldsWithErrors += "negative-trust"
+ if (cantSetOption { soneRequest.core.preferences.newPositiveTrust = positiveTrust }) fieldsWithErrors += "positive-trust"
+ if (cantSetOption { soneRequest.core.preferences.newTrustComment = trustComment }) fieldsWithErrors += "trust-comment"
if (fieldsWithErrors.isEmpty()) {
- webInterface.core.touchConfiguration()
+ soneRequest.core.touchConfiguration()
throw RedirectException("options.html")
}
templateContext["fieldErrors"] = fieldsWithErrors
}
- getCurrentSone(freenetRequest.toadletContext)?.options?.let { options ->
+ getCurrentSone(soneRequest.toadletContext)?.options?.let { options ->
templateContext["auto-follow"] = options.isAutoFollow
templateContext["show-notification-new-sones"] = options.isShowNewSoneNotifications
templateContext["show-notification-new-posts"] = options.isShowNewPostNotifications
templateContext["load-linked-images"] = options.loadLinkedImages.toString()
templateContext["show-custom-avatars"] = options.showCustomAvatars.toString()
}
- webInterface.core.preferences.let { preferences ->
+ soneRequest.core.preferences.let { preferences ->
templateContext["insertion-delay"] = preferences.insertionDelay
templateContext["characters-per-post"] = preferences.charactersPerPost
templateContext["fcp-full-access-required"] = preferences.fcpFullAccessRequired.ordinal
}
}
- private fun cantSetOption(setter: (Preferences) -> Unit) =
+ private fun cantSetOption(setter: () -> Unit) =
try {
- setter(webInterface.core.preferences)
+ setter()
false
} catch (iae: IllegalArgumentException) {
true
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class RescuePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- val soneRescuer = webInterface.core.getSoneRescuer(currentSone)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ val soneRescuer = soneRequest.core.getSoneRescuer(currentSone)
templateContext["soneRescuer"] = soneRescuer
- if (freenetRequest.isPOST) {
- freenetRequest.parameters["edition", 9]?.toIntOrNull()?.also {
+ if (soneRequest.isPOST) {
+ soneRequest.parameters["edition", 9]?.toIntOrNull()?.also {
if (it > -1) {
soneRescuer.setEdition(it.toLong())
}
}
- if (freenetRequest.parameters["fetch", 8] == "true") {
+ if (soneRequest.parameters["fetch", 8] == "true") {
soneRescuer.startNextFetch()
}
throw RedirectException("rescue.html")
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.sone.web.pages.SearchPage.Optionality.FORBIDDEN
import net.pterodactylus.sone.web.pages.SearchPage.Optionality.OPTIONAL
import net.pterodactylus.sone.web.pages.SearchPage.Optionality.REQUIRED
private val cache: Cache<Iterable<Phrase>, Pagination<Post>> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build()
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
val startTime = System.currentTimeMillis()
val phrases = try {
- freenetRequest.parameters["query"].emptyToNull?.parse()
+ soneRequest.parameters["query"].emptyToNull?.parse()
} catch (te: TextException) {
redirect("index.html")
}
0 -> redirect("index.html")
1 -> phrases.first().phrase.also { word ->
when {
- word.removePrefix("sone://").let(webInterface.core::getSone) != null -> redirect("viewSone.html?sone=${word.removePrefix("sone://")}")
- word.removePrefix("post://").let(webInterface.core::getPost) != null -> redirect("viewPost.html?post=${word.removePrefix("post://")}")
- word.removePrefix("reply://").let(webInterface.core::getPostReply) != null -> redirect("viewPost.html?post=${word.removePrefix("reply://").let(webInterface.core::getPostReply)?.postId}")
- word.removePrefix("album://").let(webInterface.core::getAlbum) != null -> redirect("imageBrowser.html?album=${word.removePrefix("album://")}")
- word.removePrefix("image://").let { webInterface.core.getImage(it, false) } != null -> redirect("imageBrowser.html?image=${word.removePrefix("image://")}")
+ word.removePrefix("sone://").let(soneRequest.core::getSone) != null -> redirect("viewSone.html?sone=${word.removePrefix("sone://")}")
+ word.removePrefix("post://").let(soneRequest.core::getPost) != null -> redirect("viewPost.html?post=${word.removePrefix("post://")}")
+ word.removePrefix("reply://").let(soneRequest.core::getPostReply) != null -> redirect("viewPost.html?post=${word.removePrefix("reply://").let(soneRequest.core::getPostReply)?.postId}")
+ word.removePrefix("album://").let(soneRequest.core::getAlbum) != null -> redirect("imageBrowser.html?album=${word.removePrefix("album://")}")
+ word.removePrefix("image://").let { soneRequest.core.getImage(it, false) } != null -> redirect("imageBrowser.html?image=${word.removePrefix("image://")}")
}
}
}
val soneNameCache = { sone: Sone -> sone.names() }.memoize()
- val sonePagination = webInterface.core.sones
- .scoreAndPaginate(phrases) { it.allText(soneNameCache) }
- .apply { page = freenetRequest.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
+ val sonePagination = soneRequest.core.sones
+ .scoreAndPaginate(phrases, soneRequest.core.preferences.postsPerPage) { it.allText(soneNameCache) }
+ .apply { page = soneRequest.parameters["sonePage"].emptyToNull?.toIntOrNull() ?: 0 }
val postPagination = cache.get(phrases) {
- webInterface.core.sones
+ soneRequest.core.sones
.flatMap(Sone::getPosts)
.filter { Post.FUTURE_POSTS_FILTER.apply(it) }
- .scoreAndPaginate(phrases) { it.allText(soneNameCache) }
- }.apply { page = freenetRequest.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
+ .scoreAndPaginate(phrases, soneRequest.core.preferences.postsPerPage) { it.allText(soneNameCache, soneRequest.core::getReplies) }
+ }.apply { page = soneRequest.parameters["postPage"].emptyToNull?.toIntOrNull() ?: 0 }
- Logger.normal(SearchPage::class.java, "Finished search for “${freenetRequest.parameters["query"]}” in ${System.currentTimeMillis() - startTime}ms.")
+ Logger.normal(SearchPage::class.java, "Finished search for “${soneRequest.parameters["query"]}” in ${System.currentTimeMillis() - startTime}ms.")
templateContext["sonePagination"] = sonePagination
templateContext["soneHits"] = sonePagination.items
templateContext["postPagination"] = postPagination
templateContext["postHits"] = postPagination.items
}
- private fun <T> Iterable<T>.scoreAndPaginate(phrases: Iterable<Phrase>, texter: (T) -> String) =
+ private fun <T> Iterable<T>.scoreAndPaginate(phrases: Iterable<Phrase>, postsPerPage: Int, texter: (T) -> String) =
map { it to score(texter(it), phrases) }
.filter { it.second > 0 }
.sortedByDescending { it.second }
.map { it.first }
- .paginate(webInterface.core.preferences.postsPerPage)
+ .paginate(postsPerPage)
private fun Sone.names() =
with(profile) {
private fun Sone.allText(soneNameCache: (Sone) -> String) =
(soneNameCache(this) + profile.fields.map { "${it.name} ${it.value}" }.joinToString(" ", " ")).toLowerCase()
- private fun Post.allText(soneNameCache: (Sone) -> String) =
- (text + recipient.orNull()?.let { " ${soneNameCache(it)}" } + webInterface.core.getReplies(id)
+ private fun Post.allText(soneNameCache: (Sone) -> String, getReplies: (String) -> Collection<PostReply>) =
+ (text + recipient.orNull()?.let { " ${soneNameCache(it)}" } + getReplies(id)
.filter { PostReply.FUTURE_REPLY_FILTER.apply(it) }
.map { "${soneNameCache(it.sone)} ${it.text}" }.joinToString(" ", " ")).toLowerCase()
*/
open class SoneTemplatePage @JvmOverloads constructor(
path: String,
- protected val webInterface: WebInterface,
+ private val webInterface: WebInterface,
template: Template,
private val pageTitleKey: String? = null,
private val requiresLogin: Boolean = false,
handleRequest(freenetRequest, templateContext)
}
- internal open fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ open fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
handleRequest(freenetRequest.toSoneRequest(core, webInterface), templateContext)
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class TrustPage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- webInterface.core.getSone(freenetRequest.parameters["sone"]!!)?.let { sone ->
- webInterface.core.trustSone(currentSone, sone)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.core.getSone(soneRequest.parameters["sone"]!!)?.let { sone ->
+ soneRequest.core.trustSone(currentSone, sone)
}
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("unbookmark.html", webInterface, template, "Page.Unbookmark.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
when {
- freenetRequest.isGET && (freenetRequest.parameters["post"] == "allNotLoaded") -> {
- webInterface.core.bookmarkedPosts
+ soneRequest.isGET && (soneRequest.parameters["post"] == "allNotLoaded") -> {
+ soneRequest.core.bookmarkedPosts
.filterNot(Post::isLoaded)
- .forEach(webInterface.core::unbookmarkPost)
+ .forEach(soneRequest.core::unbookmarkPost)
throw RedirectException("bookmarks.html")
}
- freenetRequest.isPOST -> {
- freenetRequest.parameters["post", 36]
- ?.let(webInterface.core::getPost)
- ?.also(webInterface.core::unbookmarkPost)
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ soneRequest.isPOST -> {
+ soneRequest.parameters["post", 36]
+ ?.let(soneRequest.core::getPost)
+ ?.also(soneRequest.core::unbookmarkPost)
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- freenetRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
- .forEach { webInterface.core.unfollowSone(currentSone, it) }
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
+ .forEach { soneRequest.core.unfollowSone(currentSone, it) }
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- when (freenetRequest.parameters["type"]) {
- "post" -> currentSone.removeLikedPostId(freenetRequest.parameters["post"]!!)
- "reply" -> currentSone.removeLikedReplyId(freenetRequest.parameters["reply"]!!)
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ when (soneRequest.parameters["type"]) {
+ "post" -> currentSone.removeLikedPostId(soneRequest.parameters["post"]!!)
+ "reply" -> currentSone.removeLikedReplyId(soneRequest.parameters["reply"]!!)
}
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("unlockSone.html", webInterface, template, "Page.UnlockSone.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- freenetRequest.parameters["sone", 44]
- .let(webInterface.core::getLocalSone)
- ?.also(webInterface.core::unlockSone)
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.parameters["sone", 44]
+ .let(soneRequest.core::getLocalSone)
+ ?.also(soneRequest.core::unlockSone)
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
import net.pterodactylus.sone.utils.isPOST
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface) :
LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- freenetRequest.parameters["sone", 44]!!
- .let(webInterface.core::getSone)
- ?.also { webInterface.core.untrustSone(currentSone, it) }
- throw RedirectException(freenetRequest.parameters["returnPage", 256])
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ soneRequest.parameters["sone", 44]!!
+ .let(soneRequest.core::getSone)
+ ?.also { soneRequest.core.untrustSone(currentSone, it) }
+ throw RedirectException(soneRequest.parameters["returnPage", 256])
}
}
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.utils.use
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import java.awt.image.BufferedImage
class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface):
LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface) {
- override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
- if (freenetRequest.isPOST) {
- val parentAlbum = freenetRequest.parameters["parent"]!!.let(webInterface.core::getAlbum) ?: throw RedirectException("noPermission.html")
+ override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
+ if (soneRequest.isPOST) {
+ val parentAlbum = soneRequest.parameters["parent"]!!.let(soneRequest.core::getAlbum) ?: throw RedirectException("noPermission.html")
if (parentAlbum.sone != currentSone) {
throw RedirectException("noPermission.html")
}
- val title = freenetRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
+ val title = soneRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
- val uploadedFile = freenetRequest.httpRequest.getUploadedFile("image")
+ val uploadedFile = soneRequest.httpRequest.getUploadedFile("image")
val bytes = uploadedFile.data.use { it.toByteArray() }
val bufferedImage = bytes.toImage()
if (bufferedImage == null) {
- templateContext["messages"] = webInterface.l10n.getString("Page.UploadImage.Error.InvalidImage")
+ templateContext["messages"] = soneRequest.l10n.getString("Page.UploadImage.Error.InvalidImage")
return
}
- val temporaryImage = webInterface.core.createTemporaryImage(bytes.mimeType, bytes)
- webInterface.core.createImage(currentSone, parentAlbum, temporaryImage).modify().apply {
+ val temporaryImage = soneRequest.core.createTemporaryImage(bytes.mimeType, bytes)
+ soneRequest.core.createImage(currentSone, parentAlbum, temporaryImage).modify().apply {
setWidth(bufferedImage.width)
setHeight(bufferedImage.height)
setTitle(title)
- setDescription(TextFilter.filter(freenetRequest.headers["Host"], freenetRequest.parameters["description", 4000]))
+ setDescription(TextFilter.filter(soneRequest.headers["Host"], soneRequest.parameters["description", 4000]))
}.update()
throw RedirectException("imageBrowser.html?album=${parentAlbum.id}")
}
class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("viewPost.html", webInterface, template, "Page.ViewPost.Title") {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)
- templateContext["raw"] = freenetRequest.parameters["raw"] == "true"
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ templateContext["post"] = soneRequest.parameters["post"]?.let(soneRequest.core::getPost)
+ templateContext["raw"] = soneRequest.parameters["raw"] == "true"
}
override fun isLinkExcepted(link: URI) = true
- override fun getPageTitle(freenetRequest: FreenetRequest) =
- (freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.let {
+ override fun getPageTitle(soneRequest: SoneRequest) =
+ (soneRequest.parameters["post"]?.let(soneRequest.core::getPost)?.let {
if (it.text.length > 20) {
it.text.substring(0..19) + "…"
} else {
it.text
} + " - ${SoneAccessor.getNiceName(it.sone)} - "
- } ?: "") + super.getPageTitle(freenetRequest)
+ } ?: "") + super.getPageTitle(soneRequest)
}
import net.pterodactylus.sone.utils.paginate
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import net.pterodactylus.util.template.TemplateContext
import java.net.URI
class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface):
SoneTemplatePage("viewSone.html", webInterface, template) {
- override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
- templateContext["soneId"] = freenetRequest.parameters["sone"]
- freenetRequest.parameters["sone"]!!.let(webInterface.core::getSone)?.let { sone ->
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ templateContext["soneId"] = soneRequest.parameters["sone"]
+ soneRequest.parameters["sone"]!!.let(soneRequest.core::getSone)?.let { sone ->
templateContext["sone"] = sone
val sonePosts = sone.posts
- val directedPosts = webInterface.core.getDirectedPosts(sone.id)
+ val directedPosts = soneRequest.core.getDirectedPosts(sone.id)
(sonePosts + directedPosts)
.sortedByDescending(Post::getTime)
- .paginate(webInterface.core.preferences.postsPerPage)
- .apply { page = freenetRequest.parameters["postPage"]?.toIntOrNull() ?: 0 }
+ .paginate(soneRequest.core.preferences.postsPerPage)
+ .apply { page = soneRequest.parameters["postPage"]?.toIntOrNull() ?: 0 }
.also {
templateContext["postPagination"] = it
templateContext["posts"] = it.items
.distinct()
.minus(sonePosts)
.minus(directedPosts)
- .sortedByDescending { webInterface.core.getReplies(it.id).first().time }
- .paginate(webInterface.core.preferences.postsPerPage)
- .apply { page = freenetRequest.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
+ .sortedByDescending { soneRequest.core.getReplies(it.id).first().time }
+ .paginate(soneRequest.core.preferences.postsPerPage)
+ .apply { page = soneRequest.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
.also {
templateContext["repliedPostPagination"] = it
templateContext["repliedPosts"] = it.items
override fun isLinkExcepted(link: URI) = true
- override fun getPageTitle(freenetRequest: FreenetRequest): String =
- freenetRequest.parameters["sone"]!!.let(webInterface.core::getSone)?.let { sone ->
- "${SoneAccessor.getNiceName(sone)} - ${webInterface.l10n.getString("Page.ViewSone.Title")}"
- } ?: webInterface.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")
+ override fun getPageTitle(soneRequest: SoneRequest): String =
+ soneRequest.parameters["sone"]!!.let(soneRequest.core::getSone)?.let { sone ->
+ "${SoneAccessor.getNiceName(sone)} - ${soneRequest.l10n.getString("Page.ViewSone.Title")}"
+ } ?: soneRequest.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")
}
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.DeleteSone.Title")).thenReturn("delete sone page")
- assertThat(page.getPageTitle(freenetRequest), equalTo("delete sone page"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("delete sone page"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.DismissNotification.Title")).thenReturn("dismiss notification page")
- assertThat(page.getPageTitle(freenetRequest), equalTo("dismiss notification page"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("dismiss notification page"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.Distrust.Title")).thenReturn("distrust page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("distrust page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("distrust page title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.EditAlbum.Title")).thenReturn("edit album page")
- assertThat(page.getPageTitle(freenetRequest), equalTo("edit album page"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("edit album page"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.EditImage.Title")).thenReturn("edit image page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("edit image page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("edit image page title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.EditProfileField.Title")).thenReturn("edit profile field title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("edit profile field title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("edit profile field title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.EditProfile.Title")).thenReturn("edit profile page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("edit profile page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("edit profile page title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.FollowSone.Title")).thenReturn("follow sone page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("follow sone page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("follow sone page title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.ImageBrowser.Title")).thenReturn("image browser page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("image browser page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("image browser page title"))
}
@Test
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.Index.Title")).thenReturn("index page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("index page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("index page title"))
}
@Before
@Test
fun `page returns correct title`() {
whenever(l10n.getString("Page.KnownSones.Title")).thenReturn("known sones page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("known sones page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("known sones page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Like.Title", "like page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("like page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("like page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.LockSone.Title", "lock Sone page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("lock Sone page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("lock Sone page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Logout.Title", "logout page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("logout page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("logout page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.MarkAsKnown.Title", "mark as known page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("mark as known page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("mark as known page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.New.Title", "new page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("new page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("new page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Options.Title", "options page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("options page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("options page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Rescue.Title", "rescue page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("rescue page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("rescue page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Search.Title", "search page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("search page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("search page title"))
}
@Test
@Test
fun `page title is empty string if no page title key was given`() {
SoneTemplatePage("path.html", webInterface, template, requiresLogin = false).let { page ->
- assertThat(page.getPageTitle(freenetRequest), equalTo(""))
+ assertThat(page.getPageTitle(soneRequest), equalTo(""))
}
}
fun `page title is retrieved from l10n if page title key is given`() {
SoneTemplatePage("path.html", webInterface, template, "page.title", false).let { page ->
whenever(l10n.getString("page.title")).thenReturn("Page Title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("Page Title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("Page Title"))
}
}
@Test
fun `page returns correct title`() {
addTranslation("Page.Trust.Title", "title trust page")
- assertThat(page.getPageTitle(freenetRequest), equalTo("title trust page"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("title trust page"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Unbookmark.Title", "unbookmark page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("unbookmark page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("unbookmark page title"))
}
@Test
@Test
fun `page returns correct page title`() {
addTranslation("Page.UnfollowSone.Title", "unfollow page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("unfollow page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("unfollow page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Unlike.Title", "unlike page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("unlike page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("unlike page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.UnlockSone.Title", "unlock page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("unlock page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("unlock page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.Untrust.Title", "untrust page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("untrust page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("untrust page title"))
}
@Test
@Test
fun `page returns correct title`() {
addTranslation("Page.UploadImage.Title", "upload image page title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("upload image page title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("upload image page title"))
}
@Test
@Test
fun `page title for request without parameters is default title`() {
addTranslation("Page.ViewPost.Title", "view post title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("view post title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("view post title"))
}
@Test
fun `page title for request with invalid post is default title`() {
addHttpRequestParameter("post", "invalid-post-id")
addTranslation("Page.ViewPost.Title", "view post title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("view post title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("view post title"))
}
@Test
addPost("post-id", post)
addHttpRequestParameter("post", "post-id")
addTranslation("Page.ViewPost.Title", "view post title")
- assertThat(page.getPageTitle(freenetRequest), equalTo("This is a text that … - First M. Last - view post title"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("This is a text that … - First M. Last - view post title"))
}
@Test
@Test
fun `page title is default for request without parameters`() {
addTranslation("Page.ViewSone.Page.TitleWithoutSone", "view sone page without sone")
- assertThat(page.getPageTitle(freenetRequest), equalTo("view sone page without sone"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("view sone page without sone"))
}
@Test
fun `page title is default for request with invalid sone parameters`() {
addHttpRequestParameter("sone", "invalid-sone-id")
addTranslation("Page.ViewSone.Page.TitleWithoutSone", "view sone page without sone")
- assertThat(page.getPageTitle(freenetRequest), equalTo("view sone page without sone"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("view sone page without sone"))
}
@Test
lastName = "Last"
})
addTranslation("Page.ViewSone.Title", "view sone page")
- assertThat(page.getPageTitle(freenetRequest), equalTo("First M. Last - view sone page"))
+ assertThat(page.getPageTitle(soneRequest), equalTo("First M. Last - view sone page"))
}
@Test
whenever(freenetRequest.l10n).thenReturn(l10n)
whenever(freenetRequest.uri).thenReturn(mock())
}
+ val soneRequest by lazy { freenetRequest.toSoneRequest(core, webInterface) }
val templateContext = TemplateContext()
val toadletContext = deepMock<ToadletContext>()
val responseContent = ByteArrayOutputStream()