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 {
});
/* 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);
return $("#sone .reply#" + replyId).length > 0;
}
-function loadNewPost(postId) {
+function loadNewPost(postId, soneId, recipientId, time) {
if (hasPost(postId)) {
return;
}
- if (!isIndexPage() && (!isViewPostPage() || (getShownPostId() != postId))) {
+ 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) {
newPost = $(data.post.html).addClass("hidden");
if (firstOlderPost != null) {
newPost.insertBefore(firstOlderPost);
- } else {
- $("#sone #posts").append(newPost);
}
ajaxifyPost(newPost);
newPost.slideDown();
});
}
-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) {
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();
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();