+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.database;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-
-/**
- * Builder for {@link Post} objects.
- * <p>
- * A {@link Post} consists of the following elements:
- * <ul>
- * <li>an ID,</li>
- * <li>a {@link Sone sender},</li>
- * <li>an optional {@link Sone recipient},</li>
- * <li>a time,</li>
- * <li>and a text.</li>
- * </ul>
- * 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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-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.
- * <p>
- * The following conditions must be met in order for this builder to be
- * configured correctly:
- * <ul>
- * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
- * have been called.</li>
- * <li>The {@link #from(String) sender} must not be {@code null}.</li>
- * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
- * have been called.</li>
- * <li>The {@link #withText(String) text} must not be {@code null} and must
- * contain something other than whitespace.</li>
- * <li>The {@link #to(String) recipient} must either not have been set, or
- * it must have been set to a {@link Sone} other than {@link #from(String)
- * the sender}.</li>
- * </ul>
- *
- * @return A new post
- * @throws IllegalStateException
- * if this builder’s configuration is not valid
- */
- public Post build() throws IllegalStateException;
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.database;
-
-import net.pterodactylus.sone.database.memory.MemoryDatabase;
-
-import com.google.inject.ImplementedBy;
-
-/**
- * Factory for {@link PostBuilder}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-@ImplementedBy(MemoryDatabase.class)
-public interface PostBuilderFactory {
-
- /**
- * Creates a new post builder.
- *
- * @return A new post builder
- */
- public PostBuilder newPostBuilder();
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.database;
-
-/**
- * Combines a {@link PostProvider}, a {@link PostBuilderFactory}, and a
- * {@link PostStore} into a complete post database.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostDatabase extends PostProvider, PostBuilderFactory, PostStore {
-
- /* nothing here. */
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-@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<Post> 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<Post> 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<Post> getDirectedPosts(String recipientId);
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-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);
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database
+
+/**
+ * Combines a [PostProvider], a [PostBuilderFactory], and a
+ * [PostStore] into a complete post database.
+ */
+interface PostDatabase : PostProvider, PostBuilderFactory, PostStore
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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<Post>
+ fun getPosts(soneId: String): Collection<Post>
+ fun getDirectedPosts(recipientId: String): Collection<Post>
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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)
+
+}
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["post"]
- .let(core::getPost)
+ ?.let(core::getPost)
?.let { post ->
post.sone.isLocal.ifTrue {
createSuccessJsonObject().also {
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")
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,
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 } })
}
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() }
}
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])
}
}
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 {