From 4a74200598acbc920892740918d2d2637c80fd1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Oct 2017 13:18:12 +0200 Subject: [PATCH] Replace post-specific interfaces with Kotlin versions --- .../pterodactylus/sone/database/PostBuilder.java | 144 --------------------- .../sone/database/PostBuilderFactory.java | 39 ------ .../pterodactylus/sone/database/PostDatabase.java | 30 ----- .../pterodactylus/sone/database/PostProvider.java | 64 --------- .../net/pterodactylus/sone/database/PostStore.java | 48 ------- .../net/pterodactylus/sone/database/PostBuilder.kt | 75 +++++++++++ .../sone/database/PostBuilderFactory.kt | 32 +++++ .../pterodactylus/sone/database/PostDatabase.kt | 24 ++++ .../pterodactylus/sone/database/PostProvider.kt | 36 ++++++ .../net/pterodactylus/sone/database/PostStore.kt | 31 +++++ .../sone/web/ajax/DeletePostAjaxPage.kt | 2 +- .../sone/web/ajax/GetLikesAjaxPage.kt | 2 +- .../pterodactylus/sone/web/ajax/GetPostAjaxPage.kt | 4 +- .../sone/web/ajax/GetTimesAjaxPage.kt | 2 +- .../pterodactylus/sone/web/ajax/LikeAjaxPage.kt | 2 +- .../pterodactylus/sone/web/pages/UnbookmarkPage.kt | 4 +- .../pterodactylus/sone/web/pages/ViewPostPage.kt | 4 +- 17 files changed, 208 insertions(+), 335 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostBuilder.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostDatabase.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostProvider.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostStore.java create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostBuilder.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostBuilderFactory.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostDatabase.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostStore.kt diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostBuilder.java deleted file mode 100644 index 45cc062..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostBuilder.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Sone - PostBuilder.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; - -/** - * Builder for {@link Post} objects. - *

- * A {@link Post} consists of the following elements: - *

- * Except for the recipient, all this elements have to be configured on this - * builder. For the ID you have the possibility to configure either a random ID - * (which should be used for new posts) or a custom ID you specify (for creating - * an existing post). For the time you can use the current time (again, for - * creating new posts) or the given time (for loading posts). It is an error to - * specify both ways for either the ID or the time. - * - * @author David ‘Bombe’ Roden - */ -public interface PostBuilder { - - /** - * Copies all attributes of the given post to this post builder. - * - * @param post - * The post whose attributes to copy into this builder - * @return This builder - * @throws NullPointerException - * if {@code post} is {@code null} - */ - public PostBuilder copyPost(Post post) throws NullPointerException; - - /** - * Configures this builder to use the given Sone as sender of the new post. - * - * @param senderId - * The ID of the sender of the post - * @return This post builder - */ - public PostBuilder from(String senderId); - - /** - * Configures this builder to use a random ID for the new post. If this - * method is used, {@link #withId(String)} must not be used. - * - * @return This post builder - */ - public PostBuilder randomId(); - - /** - * Configures this builder to use the given ID as ID for the new post. If - * this method is used, {@link #randomId()} must not be used. - * - * @param id - * The ID to use for the post - * @return This post builder - */ - public PostBuilder withId(String id); - - /** - * Configures this builder to use the current time when creating the post. - * If this method is used, {@link #withTime(long)} must not be used. - * - * @return This post builder - */ - public PostBuilder currentTime(); - - /** - * Configures the builder to use the given time as time for the new post. If - * this method is used, {@link #currentTime()} must not be used. - * - * @param time - * The time to use for the post - * @return This post builder - */ - public PostBuilder withTime(long time); - - /** - * Configures the builder to use the given text for the new post. - * - * @param text - * The text to use for the post - * @return This post builder - */ - public PostBuilder withText(String text); - - /** - * Configures the builder to use the given {@link Sone} as recipient for the - * post. - * - * @param recipientId - * The ID of the recipient of the post - * @return This post builder - */ - public PostBuilder to(String recipientId); - - /** - * Verifies this builder’s configuration and creates a new post. - *

- * The following conditions must be met in order for this builder to be - * configured correctly: - *

- * - * @return A new post - * @throws IllegalStateException - * if this builder’s configuration is not valid - */ - public Post build() throws IllegalStateException; - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java deleted file mode 100644 index e5cee38..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Sone - PostBuilderFactory.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import net.pterodactylus.sone.database.memory.MemoryDatabase; - -import com.google.inject.ImplementedBy; - -/** - * Factory for {@link PostBuilder}s. - * - * @author David ‘Bombe’ Roden - */ -@ImplementedBy(MemoryDatabase.class) -public interface PostBuilderFactory { - - /** - * Creates a new post builder. - * - * @return A new post builder - */ - public PostBuilder newPostBuilder(); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java deleted file mode 100644 index 648c77e..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Sone - PostDatabase.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -/** - * Combines a {@link PostProvider}, a {@link PostBuilderFactory}, and a - * {@link PostStore} into a complete post database. - * - * @author David ‘Bombe’ Roden - */ -public interface PostDatabase extends PostProvider, PostBuilderFactory, PostStore { - - /* nothing here. */ - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostProvider.java b/src/main/java/net/pterodactylus/sone/database/PostProvider.java deleted file mode 100644 index bea59b9..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Sone - PostProvider.java - Copyright © 2011–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.Collection; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.database.memory.MemoryDatabase; - -import com.google.common.base.Optional; -import com.google.inject.ImplementedBy; - -/** - * Interface for objects that can provide {@link Post}s by their ID. - * - * @author David ‘Bombe’ Roden - */ -@ImplementedBy(MemoryDatabase.class) -public interface PostProvider { - - /** - * Returns the post with the given ID. - * - * @param postId - * The ID of the post to return - * @return The post with the given ID, or {@code null} - */ - public Optional getPost(String postId); - - /** - * Returns all posts from the given Sone. - * - * @param soneId - * The ID of the Sone - * @return All posts from the given Sone - */ - public Collection getPosts(String soneId); - - /** - * Returns all posts that have the given Sone as recipient. - * - * @see Post#getRecipient() - * @param recipientId - * The ID of the recipient of the posts - * @return All posts that have the given Sone as recipient - */ - public Collection getDirectedPosts(String recipientId); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostStore.java b/src/main/java/net/pterodactylus/sone/database/PostStore.java deleted file mode 100644 index 7c3e07f..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostStore.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sone - PostStore.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.Collection; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; - -/** - * Interface for a store for posts. - * - * @author David ‘Bombe’ Roden - */ -public interface PostStore { - - /** - * Adds the given post to the store. - * - * @param post - * The post to store - */ - public void storePost(Post post); - - /** - * Removes the given post. - * - * @param post - * The post to remove - */ - public void removePost(Post post); - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostBuilder.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostBuilder.kt new file mode 100644 index 0000000..c1377ca --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostBuilder.kt @@ -0,0 +1,75 @@ +/* + * Sone - PostBuilder.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.Sone + +/** + * Builder for [Post] objects. + * + * + * A [Post] consists of the following elements: + * + * * an ID, + * * a [sender][Sone], + * * an optional [recipient][Sone], + * * a time, + * * and a text. + * + * Except for the recipient, all this elements have to be configured on this + * builder. For the ID you have the possibility to configure either a random ID + * (which should be used for new posts) or a custom ID you specify (for creating + * an existing post). For the time you can use the current time (again, for + * creating new posts) or the given time (for loading posts). It is an error to + * specify both ways for either the ID or the time. + */ +interface PostBuilder { + + fun copyPost(post: Post): PostBuilder + + fun from(senderId: String): PostBuilder + + fun randomId(): PostBuilder + fun withId(id: String): PostBuilder + + fun currentTime(): PostBuilder + fun withTime(time: Long): PostBuilder + + fun withText(text: String): PostBuilder + + fun to(recipientId: String): PostBuilder + + /** + * Verifies this builder’s configuration and creates a new post. + * + * The following conditions must be met in order for this builder to be + * configured correctly: + * + * * Exactly one of [randomId] or [withId] must have been called. + * * The [sender][from] must not be `null`. + * * Exactly one of [currentTime] or [withTime] must have been called. + * * The [text][withText] must not be `null` and must contain something other than whitespace. + * * The [recipient][to] must either not have been set, or it must have been set to a [Sone] other than [the sender][from]. + * + * @return A new post + * @throws IllegalStateException if this builder’s configuration is not valid + */ + fun build(): Post + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostBuilderFactory.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostBuilderFactory.kt new file mode 100644 index 0000000..d7604c3 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostBuilderFactory.kt @@ -0,0 +1,32 @@ +/* + * Sone - PostBuilderFactory.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.database.memory.MemoryDatabase + +import com.google.inject.ImplementedBy + +/** + * Factory for [PostBuilder]s. + */ +@ImplementedBy(MemoryDatabase::class) +interface PostBuilderFactory { + + fun newPostBuilder(): PostBuilder + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostDatabase.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostDatabase.kt new file mode 100644 index 0000000..7b97c6a --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostDatabase.kt @@ -0,0 +1,24 @@ +/* + * Sone - PostDatabase.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +/** + * Combines a [PostProvider], a [PostBuilderFactory], and a + * [PostStore] into a complete post database. + */ +interface PostDatabase : PostProvider, PostBuilderFactory, PostStore diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt new file mode 100644 index 0000000..fba9daf --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt @@ -0,0 +1,36 @@ +/* + * Sone - PostProvider.java - Copyright © 2011–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.database.memory.MemoryDatabase + +import com.google.common.base.Optional +import com.google.inject.ImplementedBy + +/** + * Interface for objects that can provide [Post]s by their ID. + */ +@ImplementedBy(MemoryDatabase::class) +interface PostProvider { + + fun getPost(postId: String): Optional + fun getPosts(soneId: String): Collection + fun getDirectedPosts(recipientId: String): Collection + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostStore.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostStore.kt new file mode 100644 index 0000000..3cb5f17 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostStore.kt @@ -0,0 +1,31 @@ +/* + * Sone - PostStore.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.Sone + +/** + * Interface for a store for posts. + */ +interface PostStore { + + fun storePost(post: Post) + fun removePost(post: Post) + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt index 76d867e..6dcf032 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.kt @@ -14,7 +14,7 @@ class DeletePostAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("deleteP override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["post"] - .let(core::getPost) + ?.let(core::getPost) ?.let { post -> post.sone.isLocal.ifTrue { createSuccessJsonObject().also { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt index cff9408..77e2c87 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.kt @@ -20,7 +20,7 @@ class GetLikesAjaxPage(webInterface: WebInterface) : JsonPage("getLikes.ajax", w override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) { "post" -> request.parameters["post"] - .let(core::getPost) + ?.let(core::getPost) ?.let(core::getLikes) ?.toReply() ?: createErrorJsonObject("invalid-post-id") diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt index 2d902a6..d91fe90 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt @@ -19,8 +19,8 @@ class GetPostAjaxPage(webInterface: WebInterface, private val postTemplate: Temp override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["post"] - .let(core::getPost) - .let { post -> + ?.let(core::getPost) + ?.let { post -> createSuccessJsonObject(). put("post", jsonObject( "id" to post.id, diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt index fb2592e..96fb7e4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -27,7 +27,7 @@ class GetTimesAjaxPage(webInterface: WebInterface, override fun createJsonObject(request: FreenetRequest) = createSuccessJsonObject().apply { - put("postTimes", request.parameters["posts"]!!.idsToJson { core.getPost(it)?.let { it.id to it.time } }) + put("postTimes", request.parameters["posts"]!!.idsToJson { core.getPost(it).let { it.id to it.time } }) put("replyTimes", request.parameters["replies"]!!.idsToJson { core.getPostReply(it)?.let { it.id to it.time } }) } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt index 576bf90..718e6e7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt @@ -14,7 +14,7 @@ class LikeAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("like.ajax", w override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = when (request.parameters["type"]) { "post" -> request.parameters["post"] - .let(core::getPost) + ?.let(core::getPost) ?.let { currentSone.addLikedPostId(it.id) } ?.also { core.touchConfiguration() } ?.let { createSuccessJsonObject() } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt index 01a0fde..c742542 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt @@ -26,8 +26,8 @@ class UnbookmarkPage(template: Template, webInterface: WebInterface): } freenetRequest.isPOST -> { freenetRequest.parameters["post", 36] - .let(webInterface.core::getPost) - .also(webInterface.core::unbookmarkPost) + ?.let(webInterface.core::getPost) + ?.also(webInterface.core::unbookmarkPost) throw RedirectException(freenetRequest.parameters["returnPage", 256]) } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt index 457e13f..d331417 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt @@ -16,14 +16,14 @@ class ViewPostPage(template: Template, webInterface: WebInterface): SoneTemplatePage("viewPost.html", template, "Page.ViewPost.Title", webInterface, false) { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { - templateContext["post"] = freenetRequest.parameters["post"].let(webInterface.core::getPost).orNull() + templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.orNull() templateContext["raw"] = freenetRequest.parameters["raw"] == "true" } override fun isLinkExcepted(link: URI?) = true public override fun getPageTitle(freenetRequest: FreenetRequest) = - (freenetRequest.parameters["post"].let(webInterface.core::getPost).let { + (freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.let { if (it.text.length > 20) { it.text.substring(0..19) + "…" } else { -- 2.7.4