Try to prevent insertion of a post or reply multiple times.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 4b60dd9..7d7bcb5 100644 (file)
@@ -497,6 +497,11 @@ function ajaxifyPost(postElement) {
                });
        });
 
+       /* mark everything as known on click. */
+       $(postElement).click(function() {
+               markPostAsKnown(this);
+       });
+
        /* hide reply input field. */
        $(postElement).find(".create-reply").addClass("hidden");
 }
@@ -526,6 +531,11 @@ function ajaxifyReply(replyElement) {
                });
        })(replyElement);
        addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time"));
+
+       /* mark post and all replies as known on click. */
+       $(replyElement).click(function() {
+               markPostAsKnown(getPostElement(replyElement));
+       });
 }
 
 /**
@@ -601,6 +611,10 @@ function loadNewPost(postId) {
        loadedPosts[postId] = true;
        $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) {
                if ((data != null) && data.success) {
+                       /* maybe weird timing stuff ensues. */
+                       if (data.post.id in loadedPosts) {
+                               return;
+                       }
                        var firstOlderPost = null;
                        $("#sone .post").each(function() {
                                if (getPostTime(this) < data.post.time) {
@@ -608,9 +622,6 @@ function loadNewPost(postId) {
                                        return false;
                                }
                        });
-                       newPost = $(data.post.html).addClass("hidden").click(function() {
-                               markPostAsKnown(this);
-                       });
                        if (firstOlderPost != null) {
                                newPost.insertBefore(firstOlderPost);
                        } else {
@@ -631,6 +642,10 @@ function loadNewReply(replyId) {
        $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) {
                /* find post. */
                if ((data != null) && data.success) {
+                       /* maybe weird timing stuff ensues. */
+                       if (data.reply.id in loadedReplies) {
+                               return;
+                       }
                        $("#sone .post#" + data.reply.postId).each(function() {
                                var firstNewerReply = null;
                                $(this).find(".replies .reply").each(function() {
@@ -639,9 +654,6 @@ function loadNewReply(replyId) {
                                                return false;
                                        }
                                });
-                               newReply = $(data.reply.html).addClass("hidden").click(function() {
-                                       markPostAsKnown(getPostElement(this));
-                               });
                                if (firstNewerReply != null) {
                                        newReply.insertBefore(firstNewerReply);
                                } else {