Mark a post and all its replies as known if a comment is added.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 936ca57..956b3df 100644 (file)
@@ -454,6 +454,8 @@ function ajaxifyPost(postElement) {
                postReply(postId, text, function(success, error, replyId) {
                        if (success) {
                                loadNewReply(replyId);
+                               markPostAsKnown(postElement);
+                               markReplyAsKnown($(postElement).find(".reply"));
                                $("#sone .post#" + postId + " .create-reply").addClass("hidden");
                        } else {
                                alert(error);
@@ -649,6 +651,24 @@ function loadNewReply(replyId) {
        });
 }
 
+function markPostAsKnown(postElements) {
+       $(postElements).each(function() {
+               postElement = this;
+               $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function() {
+                       $(postElement).removeClass("new");
+               });
+       });
+}
+
+function markReplyAsKnown(replyElements) {
+       $(replyElements).each(function() {
+               replyElement = this;
+               $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function() {
+                       $(replyElement).removeClass("new");
+               });
+       });
+}
+
 /**
  * Creates a new notification.
  *