Commit 2384339613797c1da9a60b5f329608ab27097402

Authored by Rodrigo Souto
1 parent cf12a5f2

checkpoint ensure_scroll

Showing 1 changed file with 14 additions and 1 deletions   Show diff stats
public/javascripts/chat.js
@@ -578,7 +578,7 @@ jQuery(function($) { @@ -578,7 +578,7 @@ jQuery(function($) {
578 578
579 panel.find('.history').scroll(function(){ 579 panel.find('.history').scroll(function(){
580 if($(this).scrollTop() == 0){ 580 if($(this).scrollTop() == 0){
581 - var offset = panel.find('.message').size(); 581 + var offset = panel.find('.message p').size();
582 recent_messages(jid, offset); 582 recent_messages(jid, offset);
583 } 583 }
584 }); 584 });
@@ -596,10 +596,22 @@ jQuery(function($) { @@ -596,10 +596,22 @@ jQuery(function($) {
596 return panel; 596 return panel;
597 } 597 }
598 598
  599 + function ensure_scroll(jid, offset) {
  600 + var jid_id = Jabber.jid_to_id(jid);
  601 + var history = jQuery('#conversation-'+jid_id+' .history');
  602 + // Load more messages if was not enough to show the scroll
  603 + if(history.prop('scrollHeight') - history.prop('clientHeight') <= 0){
  604 + var offset = history.find('.message p').size();
  605 + recent_messages(jid, offset);
  606 + }
  607 + }
  608 +
599 function recent_messages(jid, offset) { 609 function recent_messages(jid, offset) {
600 if(!offset) offset = 0; 610 if(!offset) offset = 0;
601 start_fetching('.history'); 611 start_fetching('.history');
602 $.getJSON('/chat/recent_messages', {identifier: getIdentifier(jid), offset: offset}, function(data) { 612 $.getJSON('/chat/recent_messages', {identifier: getIdentifier(jid), offset: offset}, function(data) {
  613 + //TODO Register if no more messages returned and stop trying to load
  614 + // more messages in the future.
603 $.each(data, function(i, message) { 615 $.each(data, function(i, message) {
604 var body = message['body']; 616 var body = message['body'];
605 var from = message['from']; 617 var from = message['from'];
@@ -610,6 +622,7 @@ jQuery(function($) { @@ -610,6 +622,7 @@ jQuery(function($) {
610 Jabber.show_message(jid, from['name'], body, who, from['id'], date, offset); 622 Jabber.show_message(jid, from['name'], body, who, from['id'], date, offset);
611 }); 623 });
612 stop_fetching('.history'); 624 stop_fetching('.history');
  625 + ensure_scroll(jid, offset);
613 }); 626 });
614 } 627 }
615 628