X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=acb1d466368e6d72e51f06f71366e7701bd439f3;hb=10ec5654f69c234c8c3586e592403ac351d0110e;hp=bed9e6684cb9c8d61dd5da905555f25c64486881;hpb=c8e5397e51af306fb6db4faa6af4887c88fae9aa;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index bed9e66..acb1d46 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -449,16 +449,18 @@ function ajaxifyPost(postElement) { inputField = $(this.form).find(":input:enabled").get(0); postId = getPostId(this); text = $(inputField).val(); - $(inputField).val(""); - postReply(postId, text, function(success, error, replyId) { - if (success) { - loadNewReply(replyId); - markPostAsKnown(getPostElement(inputField)); - $("#sone .post#" + postId + " .create-reply").addClass("hidden"); - } else { - alert(error); - } - }); + (function(postId, text, inputField) { + postReply(postId, text, function(success, error, replyId) { + if (success) { + $(inputField).val(""); + loadNewReply(replyId); + markPostAsKnown(getPostElement(inputField)); + $("#sone .post#" + postId + " .create-reply").addClass("hidden"); + } else { + alert(error); + } + }); + })(postId, text, inputField); return false; }); @@ -534,7 +536,7 @@ function ajaxifyReply(replyElement) { /* mark post and all replies as known on click. */ $(replyElement).click(function() { - markPostAsKnown(getPostElement(replyElement)); + markPostAsKnown(getPostElement(this)); }); } @@ -677,10 +679,13 @@ function loadNewPost(postId) { if (postId in loadedPosts) { return; } - loadedPosts[postId] = true; $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { - if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) { + if (data.post.id in loadedPosts) { + return; + } + loadedPosts[data.post.id] = true; + if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) { return; } var firstOlderPost = null; @@ -694,7 +699,7 @@ function loadNewPost(postId) { if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { - $("#sone .post:last").append(newPost); + $("#sone #posts").append(newPost); } ajaxifyPost(newPost); newPost.slideDown(); @@ -707,10 +712,13 @@ function loadNewReply(replyId) { if (replyId in loadedReplies) { return; } - loadedReplies[replyId] = true; $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) { /* find post. */ if ((data != null) && data.success) { + if (data.reply.id in loadedReplies) { + return; + } + loadedReplies[data.reply.id] = true; $("#sone .post#" + data.reply.postId).each(function() { var firstNewerReply = null; $(this).find(".replies .reply").each(function() { @@ -732,6 +740,7 @@ function loadNewReply(replyId) { ajaxifyReply(newReply); newReply.slideDown(); setActivity(); + return false; }); } }); @@ -830,7 +839,7 @@ $(document).ready(function() { registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false); $("#sone #post-message").submit(function() { text = $(this).find(":input:enabled").val(); - $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": $("#sone #sone-id").text(), "text": text }, function(data, textStatus) { + $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "text": text }, function(data, textStatus) { if ((data != null) && data.success) { loadNewPost(data.postId); }