Do not allow creation of empty posts and replies.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 9e1e6c6..37c026f 100644 (file)
@@ -77,6 +77,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Core.class);
 
+       /** The start time. */
+       private final long startupTime = System.currentTimeMillis();
+
        /** The options. */
        private final Options options = new Options();
 
@@ -228,6 +231,15 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        //
 
        /**
+        * Returns the time Sone was started.
+        *
+        * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
+        */
+       public long getStartupTime() {
+               return startupTime;
+       }
+
+       /**
         * Sets the configuration to use. This will automatically save the current
         * configuration to the given configuration.
         *
@@ -1148,8 +1160,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                                if (!storedPosts.contains(post)) {
                                                        if (post.getTime() < getSoneFollowingTime(sone)) {
                                                                knownPosts.add(post.getId());
+                                                               post.setKnown(true);
                                                        } else if (!knownPosts.contains(post.getId())) {
-                                                               sone.setKnown(false);
                                                                coreListenerManager.fireNewPostFound(post);
                                                        }
                                                }
@@ -1173,8 +1185,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                                if (!storedReplies.contains(reply)) {
                                                        if (reply.getTime() < getSoneFollowingTime(sone)) {
                                                                knownReplies.add(reply.getId());
+                                                               reply.setKnown(true);
                                                        } else if (!knownReplies.contains(reply.getId())) {
-                                                               reply.setKnown(false);
                                                                coreListenerManager.fireNewReplyFound(reply);
                                                        }
                                                }
@@ -1567,6 +1579,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         * @return The created post
         */
        public Post createPost(Sone sone, Sone recipient, long time, String text) {
+               Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.length(), 0).check();
                if (!isLocalSone(sone)) {
                        logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
                        return null;
@@ -1707,6 +1720,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         * @return The created reply
         */
        public PostReply createReply(Sone sone, Post post, long time, String text) {
+               Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.trim().length(), 0).check();
                if (!isLocalSone(sone)) {
                        logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
                        return null;