From 09647389dd4e7e06c0cadd78e73ec684eac73632 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 17 Dec 2014 22:14:24 +0000 Subject: [PATCH] Register when no more messages retrieved to not fetch more messages from that conversations --- public/javascripts/chat.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/public/javascripts/chat.js b/public/javascripts/chat.js index b066e29..3ed0d8e 100644 --- a/public/javascripts/chat.js +++ b/public/javascripts/chat.js @@ -27,6 +27,7 @@ jQuery(function($) { conversation_prefix: 'conversation-', jids: {}, rooms: {}, + no_more_messages: {}, template: function(selector) { return $('#chat #chat-templates '+selector).clone().html(); @@ -124,9 +125,9 @@ jQuery(function($) { var tab_id = '#' + Jabber.conversation_prefix + jid_id; var history = $(tab_id).find('.history'); - var offset_container = $('#chat-offset-container-'+offset); + var offset_container = history.find('.chat-offset-container-'+offset); if(offset_container.length == 0) - offset_container = $('
').prependTo(history); + offset_container = $('
').prependTo(history); if (offset_container.find('.message:last').attr('data-who') == who) { offset_container.find('.message:last .content').append('

' + body + '

'); @@ -536,9 +537,10 @@ jQuery(function($) { var name = Jabber.name_of(jid_id); var conversation = create_conversation_tab(name, jid_id); - conversation.find('.conversation').show(); + $('.conversation').hide(); + conversation.show(); count_unread_messages(jid_id, true); - if(conversation.find('#chat-offset-container-0').length == 0) + if(conversation.find('.chat-offset-container-0').length == 0) recent_messages(Jabber.jid_of(jid_id)); conversation.find('.conversation .input-div textarea.input').focus(); }); @@ -601,11 +603,16 @@ jQuery(function($) { } function recent_messages(jid, offset) { + if (Jabber.no_more_messages[jid]) return; + if(!offset) offset = 0; start_fetching('.history'); $.getJSON('/chat/recent_messages', {identifier: getIdentifier(jid), offset: offset}, function(data) { - //TODO Register if no more messages returned and stop trying to load - // more messages in the future. + // Register if no more messages returned and stop trying to load + // more messages in the future. + if(data.length == 0) + Jabber.no_more_messages[jid] = true; + $.each(data, function(i, message) { var body = message['body']; var from = message['from']; -- libgit2 0.21.2