Try to prevent multiple insertion of the same replies.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 3646f73..0d1772e 100644 (file)
@@ -449,9 +449,9 @@ function ajaxifyPost(postElement) {
                inputField = $(this.form).find(":input:enabled").get(0);
                postId = getPostId(this);
                text = $(inputField).val();
-               $(inputField).val("");
                postReply(postId, text, function(success, error, replyId) {
                        if (success) {
+                               $(inputField).val("");
                                loadNewReply(replyId);
                                markPostAsKnown(getPostElement(inputField));
                                $("#sone .post#" + postId + " .create-reply").addClass("hidden");
@@ -707,8 +707,11 @@ function loadNewReply(replyId) {
        if (replyId in loadedReplies) {
                return;
        }
-       loadedReplies[replyId] = true;
        $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
+               if (replyId in loadedReplies) {
+                       return;
+               }
+               loadedReplies[replyId] = true;
                /* find post. */
                if ((data != null) && data.success) {
                        $("#sone .post#" + data.reply.postId).each(function() {
@@ -732,6 +735,7 @@ function loadNewReply(replyId) {
                                ajaxifyReply(newReply);
                                newReply.slideDown();
                                setActivity();
+                               return false;
                        });
                }
        });