@@ -114,7 +114,7 @@ var Postbox = function(parent) {
114114 notification : $ ( "[name=notification]" , el ) . checked ( ) ? 1 : 0 ,
115115 } ) . then ( function ( comment ) {
116116 $ ( ".isso-textarea" , el ) . value = "" ;
117- insert ( comment , true ) ;
117+ insert ( { comment, scrollIntoView : true , offset : 0 } ) ;
118118
119119 if ( parent !== null ) {
120120 el . onsuccess ( ) ;
@@ -125,7 +125,7 @@ var Postbox = function(parent) {
125125 return el ;
126126} ;
127127
128- var insert_loader = function ( comment , lastcreated ) {
128+ var insert_loader = function ( comment , offset ) {
129129 var entrypoint ;
130130 if ( comment . id === null ) {
131131 entrypoint = $ ( "#isso-root" ) ;
@@ -140,34 +140,37 @@ var insert_loader = function(comment, lastcreated) {
140140
141141 $ ( "a.isso-load-hidden" , el ) . on ( "click" , function ( ) {
142142 el . remove ( ) ;
143- api . fetch ( $ ( "#isso-thread" ) . getAttribute ( "data-isso-id" ) ,
144- config [ "reveal-on-click" ] , config [ "max-comments-nested" ] ,
145- comment . id ,
146- lastcreated ) . then (
143+
144+ api . fetch ( {
145+ tid : $ ( "#isso-thread" ) . getAttribute ( "data-isso-id" ) ,
146+ limit : config [ "reveal-on-click" ] ,
147+ nested_limit : config [ "max-comments-nested" ] ,
148+ parent : comment . id ,
149+ sort : config [ "sorting" ] ,
150+ offset : offset
151+ } ) . then (
147152 function ( rv ) {
148153 if ( rv . total_replies === 0 ) {
149154 return ;
150155 }
151156
152- var lastcreated = 0 ;
153157 rv . replies . forEach ( function ( commentObject ) {
154- insert ( commentObject , false ) ;
155- if ( commentObject . created > lastcreated ) {
156- lastcreated = commentObject . created ;
157- }
158+ insert ( { comment : commentObject , scrollIntoView : false , offset : 0 } ) ;
159+
158160 } ) ;
159161
160162 if ( rv . hidden_replies > 0 ) {
161- insert_loader ( rv , lastcreated ) ;
163+ insert_loader ( rv , offset + rv . replies . length ) ;
162164 }
163165 } ,
164166 function ( err ) {
165167 console . log ( err ) ;
166- } ) ;
168+ }
169+ ) ;
167170 } ) ;
168171} ;
169172
170- var insert = function ( comment , scrollIntoView ) {
173+ var insert = function ( { comment, scrollIntoView, offset } ) {
171174 var el = $ . htmlify ( template . render ( "comment" , { "comment" : comment } ) ) ;
172175
173176 // update datetime every 60 seconds
@@ -381,19 +384,13 @@ var insert = function(comment, scrollIntoView) {
381384 show ( $ ( "a.isso-reply" , footer ) . detach ( ) ) ;
382385 }
383386
384- if ( comment . hasOwnProperty ( 'replies' ) ) {
385- var lastcreated = 0 ;
386- comment . replies . forEach ( function ( replyObject ) {
387- insert ( replyObject , false ) ;
388- if ( replyObject . created > lastcreated ) {
389- lastcreated = replyObject . created ;
390- }
391-
387+ if ( comment . hasOwnProperty ( 'replies' ) ) {
388+ comment . replies . forEach ( function ( replyObject ) {
389+ insert ( { comment : replyObject , scrollIntoView : false , offset : offset + 1 } ) ;
392390 } ) ;
393- if ( comment . hidden_replies > 0 ) {
394- insert_loader ( comment , lastcreated ) ;
391+ if ( comment . hidden_replies > 0 ) {
392+ insert_loader ( comment , offset + comment . replies . length ) ;
395393 }
396-
397394 }
398395
399396} ;
0 commit comments