Commit 057a8310 authored by Brion Vibber's avatar Brion Vibber

Fixes for race conditions between Realtime plugin and the AJAX display of inline replies.

* keep the notice-reply-placeholder around, but hidden
* insert things before the placeholder, rather than appending to the end of the list.
* append the active form after the hidden placeholder, so things inserted before the placeholder never come after it
* Realtime: check pre-existing notice visibility a second time after loading the HTML for a notice. Fixes bug where sometimes your own post would be shown twice because the Realtime notification arrived before the AJAX posting returned, but Realtime's AJAX fetch of the notice returned after.
parent 94ecfc3f
......@@ -412,16 +412,20 @@ var SN = { // StatusNet
var replyItem = form.closest('li.notice-reply');
if (replyItem.length > 0) {
// If this is an inline reply, insert it in place.
// If this is an inline reply, remove the form...
var list = form.closest('.threaded-replies');
var placeholder = list.find('.notice-reply-placeholder');
replyItem.remove();
var id = $(notice).attr('id');
if ($("#"+id).length == 0) {
var parentNotice = replyItem.closest('li.notice');
replyItem.replaceWith(notice);
SN.U.NoticeInlineReplyPlaceholder(parentNotice);
$(notice).insertBefore(placeholder);
} else {
// Realtime came through before us...
replyItem.remove();
}
// ...and show the placeholder form.
placeholder.show();
} else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
// Not a reply. If on our timeline, show it at the top!
......@@ -604,8 +608,8 @@ var SN = { // StatusNet
// Update the existing form...
nextStep();
} else {
// Remove placeholder if any
list.find('li.notice-reply-placeholder').remove();
// Hide the placeholder...
var placeholder = list.find('li.notice-reply-placeholder').hide();
// Create the reply form entry at the end
var replyItem = $('li.notice-reply', list);
......@@ -615,7 +619,7 @@ var SN = { // StatusNet
var intermediateStep = function(formMaster) {
var formEl = document._importNode(formMaster, true);
replyItem.append(formEl);
list.append(replyItem);
list.append(replyItem); // *after* the placeholder
var form = replyForm = $(formEl);
SN.Init.NoticeFormSetup(form);
......@@ -1360,7 +1364,7 @@ var SN = { // StatusNet
if (cur == '' || cur == textarea.data('initialText')) {
var parentNotice = replyItem.closest('li.notice');
replyItem.remove();
SN.U.NoticeInlineReplyPlaceholder(parentNotice);
parentNotice.find('li.notice-reply-placeholder').show();
}
}
});
......
This diff is collapsed.
......@@ -155,6 +155,10 @@ RealtimeUpdate = {
}
RealtimeUpdate.makeNoticeItem(data, function(noticeItem) {
// Check again in case it got shown while we were waiting for data...
if (RealtimeUpdate.isNoticeVisible(data.id)) {
return;
}
var noticeItemID = $(noticeItem).attr('id');
var list = $("#notices_primary .notices:first")
......@@ -177,6 +181,7 @@ RealtimeUpdate = {
if (list.length == 0) {
list = $('<ul class="notices threaded-replies xoxo"></ul>');
parent.append(list);
SN.U.NoticeInlineReplyPlaceholder(parent);
}
prepend = false;
}
......@@ -191,7 +196,6 @@ RealtimeUpdate = {
newNotice.insertBefore(placeholder)
} else {
newNotice.appendTo(list);
SN.U.NoticeInlineReplyPlaceholder(parent);
}
}
newNotice.css({display:"none"}).fadeIn(1000);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment