Mark post as loaded when the AJAX reply has arrived.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 33f45df..b44f19e 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");
@@ -677,8 +677,11 @@ function loadNewPost(postId) {
        if (postId in loadedPosts) {
                return;
        }
-       loadedPosts[postId] = true;
        $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
+               if (postId in loadedPosts) {
+                       return;
+               }
+               loadedPosts[postId] = true;
                if ((data != null) && data.success) {
                        if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
                                return;
@@ -707,8 +710,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() {