Commit 09647389dd4e7e06c0cadd78e73ec684eac73632
1 parent
ce7c5efc
Exists in
master
and in
29 other branches
Register when no more messages retrieved to not fetch more messages from that conversations
Showing
1 changed file
with
13 additions
and
6 deletions
Show diff stats
public/javascripts/chat.js
@@ -27,6 +27,7 @@ jQuery(function($) { | @@ -27,6 +27,7 @@ jQuery(function($) { | ||
27 | conversation_prefix: 'conversation-', | 27 | conversation_prefix: 'conversation-', |
28 | jids: {}, | 28 | jids: {}, |
29 | rooms: {}, | 29 | rooms: {}, |
30 | + no_more_messages: {}, | ||
30 | 31 | ||
31 | template: function(selector) { | 32 | template: function(selector) { |
32 | return $('#chat #chat-templates '+selector).clone().html(); | 33 | return $('#chat #chat-templates '+selector).clone().html(); |
@@ -124,9 +125,9 @@ jQuery(function($) { | @@ -124,9 +125,9 @@ jQuery(function($) { | ||
124 | var tab_id = '#' + Jabber.conversation_prefix + jid_id; | 125 | var tab_id = '#' + Jabber.conversation_prefix + jid_id; |
125 | var history = $(tab_id).find('.history'); | 126 | var history = $(tab_id).find('.history'); |
126 | 127 | ||
127 | - var offset_container = $('#chat-offset-container-'+offset); | 128 | + var offset_container = history.find('.chat-offset-container-'+offset); |
128 | if(offset_container.length == 0) | 129 | if(offset_container.length == 0) |
129 | - offset_container = $('<div id="chat-offset-container-'+offset+'"></div>').prependTo(history); | 130 | + offset_container = $('<div class="chat-offset-container-'+offset+'"></div>').prependTo(history); |
130 | 131 | ||
131 | if (offset_container.find('.message:last').attr('data-who') == who) { | 132 | if (offset_container.find('.message:last').attr('data-who') == who) { |
132 | offset_container.find('.message:last .content').append('<p>' + body + '</p>'); | 133 | offset_container.find('.message:last .content').append('<p>' + body + '</p>'); |
@@ -536,9 +537,10 @@ jQuery(function($) { | @@ -536,9 +537,10 @@ jQuery(function($) { | ||
536 | var name = Jabber.name_of(jid_id); | 537 | var name = Jabber.name_of(jid_id); |
537 | var conversation = create_conversation_tab(name, jid_id); | 538 | var conversation = create_conversation_tab(name, jid_id); |
538 | 539 | ||
539 | - conversation.find('.conversation').show(); | 540 | + $('.conversation').hide(); |
541 | + conversation.show(); | ||
540 | count_unread_messages(jid_id, true); | 542 | count_unread_messages(jid_id, true); |
541 | - if(conversation.find('#chat-offset-container-0').length == 0) | 543 | + if(conversation.find('.chat-offset-container-0').length == 0) |
542 | recent_messages(Jabber.jid_of(jid_id)); | 544 | recent_messages(Jabber.jid_of(jid_id)); |
543 | conversation.find('.conversation .input-div textarea.input').focus(); | 545 | conversation.find('.conversation .input-div textarea.input').focus(); |
544 | }); | 546 | }); |
@@ -601,11 +603,16 @@ jQuery(function($) { | @@ -601,11 +603,16 @@ jQuery(function($) { | ||
601 | } | 603 | } |
602 | 604 | ||
603 | function recent_messages(jid, offset) { | 605 | function recent_messages(jid, offset) { |
606 | + if (Jabber.no_more_messages[jid]) return; | ||
607 | + | ||
604 | if(!offset) offset = 0; | 608 | if(!offset) offset = 0; |
605 | start_fetching('.history'); | 609 | start_fetching('.history'); |
606 | $.getJSON('/chat/recent_messages', {identifier: getIdentifier(jid), offset: offset}, function(data) { | 610 | $.getJSON('/chat/recent_messages', {identifier: getIdentifier(jid), offset: offset}, function(data) { |
607 | - //TODO Register if no more messages returned and stop trying to load | ||
608 | - // more messages in the future. | 611 | + // Register if no more messages returned and stop trying to load |
612 | + // more messages in the future. | ||
613 | + if(data.length == 0) | ||
614 | + Jabber.no_more_messages[jid] = true; | ||
615 | + | ||
609 | $.each(data, function(i, message) { | 616 | $.each(data, function(i, message) { |
610 | var body = message['body']; | 617 | var body = message['body']; |
611 | var from = message['from']; | 618 | var from = message['from']; |