X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=ca087fadab83f6f8860225f2e126f74bbdec4b65;hb=edc855dd691b472f36007fc8492e0f70e3301c60;hp=803774ad0897d2144e8e5e15d7eb979c14bd7ad4;hpb=46bbcdbc69ed6c86f62cc9c3430404c8461924e0;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 803774a..ca087fa 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -453,7 +453,7 @@ function ajaxifyPost(postElement) { postReply(postId, text, function(success, error, replyId) { if (success) { $(inputField).val(""); - loadNewReply(replyId); + loadNewReply(replyId, getCurrentSoneId(), postId); markPostAsKnown(getPostElement(inputField)); $("#sone .post#" + postId + " .create-reply").addClass("hidden"); } else { @@ -585,11 +585,11 @@ function getStatus() { }); /* process new posts. */ $.each(data.newPosts, function(index, value) { - loadNewPost(value); + loadNewPost(value.id, value.sone, value.recipient); }); /* process new replies. */ $.each(data.newReplies, function(index, value) { - loadNewReply(value); + loadNewReply(value.id, value.sone, value.post, value.postSone); }); /* do it again in 5 seconds. */ setTimeout(getStatus, 5000); @@ -604,6 +604,16 @@ function getStatus() { } /** + * Returns the ID of the currently logged in Sone. + * + * @return The ID of the current Sone, or an empty string if no Sone is logged + * in + */ +function getCurrentSoneId() { + return $("#currentSoneId").text(); +} + +/** * Returns the content of the page-id attribute. * * @returns The page ID @@ -696,10 +706,17 @@ function hasReply(replyId) { return $("#sone .reply#" + replyId).length > 0; } -function loadNewPost(postId) { +function loadNewPost(postId, soneId, recipientId) { if (hasPost(postId)) { return; } + if (!isIndexPage()) { + if (!isViewPostPage() || (getShownPostId() != postId)) { + if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId))) { + return; + } + } + } $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { if (hasPost(data.post.id)) { @@ -728,10 +745,13 @@ function loadNewPost(postId) { }); } -function loadNewReply(replyId) { +function loadNewReply(replyId, soneId, postId, postSoneId) { if (hasReply(replyId)) { return; } + if (!hasPost(postId)) { + return; + } $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) { /* find post. */ if ((data != null) && data.success) { @@ -830,6 +850,17 @@ function createNotification(id, text, dismissable) { return notification; } +/** + * Shows the details of the notification with the given ID. + * + * @param notificationId + * The ID of the notification + */ +function showNotificationDetails(notificationId) { + $("#sone .notification#" + notificationId + " .text").show(); + $("#sone .notification#" + notificationId + " .short-text").hide(); +} + // // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE // @@ -848,7 +879,7 @@ $(document).ready(function() { text = $(this).find(":input:enabled").val(); $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) { if ((data != null) && data.success) { - loadNewPost(data.postId); + loadNewPost(data.postId, getCurrentSoneId()); } }); $(this).find(":input:enabled").val("").blur(); @@ -863,7 +894,7 @@ $(document).ready(function() { text = $(this).find(":input:enabled").val(); $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "text": text }, function(data, textStatus) { if ((data != null) && data.success) { - loadNewPost(data.postId); + loadNewPost(data.postId, getCurrentSoneId()); } }); $(this).find(":input:enabled").val("").blur(); @@ -954,9 +985,7 @@ $(document).ready(function() { }); /* activate status polling. */ - if ((getPageId() != undefined) && (getPageId() != "login")) { - setTimeout(getStatus, 5000); - } + setTimeout(getStatus, 5000); /* reset activity counter when the page has focus. */ $(window).focus(function() {