X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=cd34ed28259407e98acbb0c4d57db90c1d67a8b3;hb=c731d14a20122ba8c02db2381305e821ad367712;hp=2c3f742c281fdab5c74f43c6aa4e62c95c6816d6;hpb=87409ba62fa1d69f21aa91df079b8987909868d8;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 2c3f742..cd34ed2 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, value.time); }); /* 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); @@ -706,12 +706,19 @@ function hasReply(replyId) { return $("#sone .reply#" + replyId).length > 0; } -function loadNewPost(postId, soneId, recipientId) { +function loadNewPost(postId, soneId, recipientId, time) { if (hasPost(postId)) { return; } - if (!isIndexPage() && (!isViewPostPage() || (getShownPostId() != postId))) { - return; + if (!isIndexPage()) { + if (!isViewPostPage() || (getShownPostId() != postId)) { + if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId))) { + return; + } + } + if (getPostTime($("#sone .post").last()) > time) { + return; + } } $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { @@ -731,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(); @@ -741,10 +746,13 @@ function loadNewPost(postId, soneId, recipientId) { }); } -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) { @@ -872,7 +880,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(); @@ -887,7 +895,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();