Merge branch 'reduce-loading' into next
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Jan 2011 18:15:26 +0000 (19:15 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Jan 2011 19:51:55 +0000 (20:51 +0100)
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/resources/static/javascript/sone.js

index 172f237..a358fb1 100644 (file)
@@ -95,6 +95,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        jsonPost.put("id", post.getId());
                        jsonPost.put("sone", post.getSone().getId());
                        jsonPost.put("recipient", (post.getRecipient() != null) ? post.getRecipient().getId() : null);
+                       jsonPost.put("time", post.getTime());
                        jsonPosts.add(jsonPost);
                }
                /* load new replies. */
index ca087fa..3c229e0 100644 (file)
@@ -585,7 +585,7 @@ function getStatus() {
                        });
                        /* process new posts. */
                        $.each(data.newPosts, function(index, value) {
-                               loadNewPost(value.id, value.sone, value.recipient);
+                               loadNewPost(value.id, value.sone, value.recipient, value.time);
                        });
                        /* process new replies. */
                        $.each(data.newReplies, function(index, value) {
@@ -706,7 +706,7 @@ function hasReply(replyId) {
        return $("#sone .reply#" + replyId).length > 0;
 }
 
-function loadNewPost(postId, soneId, recipientId) {
+function loadNewPost(postId, soneId, recipientId, time) {
        if (hasPost(postId)) {
                return;
        }
@@ -717,6 +717,9 @@ function loadNewPost(postId, soneId, recipientId) {
                        }
                }
        }
+       if (getPostTime($("#sone .post").last()) > time) {
+               return;
+       }
        $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
                if ((data != null) && data.success) {
                        if (hasPost(data.post.id)) {
@@ -735,8 +738,6 @@ function loadNewPost(postId, soneId, recipientId) {
                        newPost = $(data.post.html).addClass("hidden");
                        if (firstOlderPost != null) {
                                newPost.insertBefore(firstOlderPost);
-                       } else {
-                               $("#sone #posts").append(newPost);
                        }
                        ajaxifyPost(newPost);
                        newPost.slideDown();