From 632116a9843914f931e6bc3e2d56a0b1961a4db9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 29 May 2012 08:55:04 +0200 Subject: [PATCH] Only process new posts and replies if the notifications changed. --- .../pterodactylus/sone/web/ajax/GetStatusAjaxPage.java | 1 + src/main/resources/static/javascript/sone.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 28fee14..223a79f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -91,6 +91,7 @@ public class GetStatusAjaxPage extends JsonPage { } /* load notifications. */ List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); + Collections.sort(notifications, Notification.CREATED_TIME_SORTER); int notificationHash = HashCode.hashCode(notifications); /* load new posts. */ Set newPosts = webInterface.getNewPosts(); diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 414dd02..6077049 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -1206,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 { -- 2.7.4