Use correct post element.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 619b62e..8a40131 100644 (file)
@@ -454,8 +454,7 @@ function ajaxifyPost(postElement) {
                postReply(postId, text, function(success, error, replyId) {
                        if (success) {
                                loadNewReply(replyId);
-                               markPostAsKnown(postElement);
-                               markReplyAsKnown($(postElement).find(".reply"));
+                               markPostAsKnown(getPostElement(inputField));
                                $("#sone .post#" + postId + " .create-reply").addClass("hidden");
                        } else {
                                alert(error);
@@ -654,18 +653,23 @@ function loadNewReply(replyId) {
 function markPostAsKnown(postElements) {
        $(postElements).each(function() {
                postElement = this;
-               $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function() {
-                       $(postElement).removeClass("new");
-               });
+               if ($(postElement).hasClass("new")) {
+                       $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
+                               $(postElement).removeClass("new");
+                       });
+               }
        });
+       markReplyAsKnown($(postElements).find(".reply"));
 }
 
 function markReplyAsKnown(replyElements) {
        $(replyElements).each(function() {
                replyElement = this;
-               $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function() {
-                       $(replyElement).removeClass("new");
-               });
+               if ($(replyElement).hasClass("new")) {
+                       $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
+                               $(replyElement).removeClass("new");
+                       });
+               }
        });
 }