Fix ticket #2914: Realtime no longer tells you it's got a message queued up when it's really the one you just sent out and is already visible.

This commit is contained in:
Brion Vibber 2010-11-30 16:46:11 -08:00
parent f222e2132d
commit c6f5975554
2 changed files with 22 additions and 5 deletions

View File

@ -112,13 +112,15 @@ RealtimeUpdate = {
*
* @param {Object} data: extended JSON API-formatted notice
*
* @fixme Ticket #2914: already-visible sent notices are still queued up
* when paused, inflating the queue count
*
* @access public
*/
receive: function(data)
{
if (RealtimeUpdate.isNoticeVisible(data.id)) {
// Probably posted by the user in this window, and so already
// shown by the AJAX form handler. Ignore it.
return;
}
if (RealtimeUpdate._paused === false) {
RealtimeUpdate.purgeLastNoticeItem();
@ -149,7 +151,7 @@ RealtimeUpdate = {
*/
insertNoticeItem: function(data) {
// Don't add it if it already exists
if ($("#notice-"+data.id).length > 0) {
if (RealtimeUpdate.isNoticeVisible(data.id)) {
return;
}
@ -164,6 +166,21 @@ RealtimeUpdate = {
SN.U.NoticeWithAttachment($('#'+noticeItemID));
},
/**
* Check if the given notice is visible in the timeline currently.
* Used to avoid duplicate processing of notices that have been
* displayed by other means.
*
* @param {number} id: notice ID to check
*
* @return boolean
*
* @access private
*/
isNoticeVisible: function(id) {
return ($("#notice-"+id).length > 0);
},
/**
* Trims a notice off the end of the timeline if we have more than the
* maximum number of notices visible.

File diff suppressed because one or more lines are too long