Only process new posts and replies if the notifications changed.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 90bd58b..6077049 100644 (file)
@@ -847,12 +847,14 @@ function ajaxifyPost(postElement) {
        });
 
        /* mark everything as known on click. */
-       $(postElement).click(function(event) {
-               if ($(event.target).hasClass("click-to-show")) {
-                       return false;
-               }
-               markPostAsKnown(this);
-       });
+       (function(postElement) {
+               $(postElement).click(function(event) {
+                       if ($(event.target).hasClass("click-to-show")) {
+                               return false;
+                       }
+                       markPostAsKnown(postElement, false);
+               });
+       })(postElement);
 
        /* hide reply input field. */
        $(postElement).find(".create-reply").addClass("hidden");
@@ -1204,15 +1206,15 @@ function getStatus() {
                        if (data.notificationHash != getNotificationHash()) {
                                console.log("Old hash: ", getNotificationHash(), ", new hash: ", data.notificationHash);
                                requestNotifications();
+                               /* process new posts. */
+                               $.each(data.newPosts, function(index, value) {
+                                       loadNewPost(value.id, value.sone, value.recipient, value.time);
+                               });
+                               /* process new replies. */
+                               $.each(data.newReplies, function(index, value) {
+                                       loadNewReply(value.id, value.sone, value.post, value.postSone);
+                               });
                        }
-                       /* process new posts. */
-                       $.each(data.newPosts, function(index, value) {
-                               loadNewPost(value.id, value.sone, value.recipient, value.time);
-                       });
-                       /* process new replies. */
-                       $.each(data.newReplies, function(index, value) {
-                               loadNewReply(value.id, value.sone, value.post, value.postSone);
-                       });
                        /* do it again in 5 seconds. */
                        setTimeout(getStatus, 5000);
                } else {
@@ -1536,7 +1538,7 @@ function markPostAsKnown(postElements, skipRequest) {
                }
                $(".click-to-show", postElement).removeClass("new");
        });
-       markReplyAsKnown($(postElements).find(".reply"));
+       markReplyAsKnown($(postElements).find(".reply"), true);
 }
 
 function markReplyAsKnown(replyElements, skipRequest) {
@@ -1947,7 +1949,7 @@ $(document).ready(function() {
                                allReplies = $(this).find(".reply");
                                if (allReplies.length > 2) {
                                        newHidden = false;
-                                       for (replyIndex = 0; !newHidden && (replyIndex < (allReplies.length - 2)); ++replyIndex) {
+                                       for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
                                                $(allReplies[replyIndex]).addClass("hidden");
                                                newHidden |= $(allReplies[replyIndex]).hasClass("new");
                                        }