@@ -113,8 +113,8 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
113113 displayed [ ele . AJAR_subject . uri ] = true
114114 }
115115 }
116-
117116 const messages = store . each ( chatChannel , ns . wf ( 'message' ) , null , messageTable . chatDocument )
117+
118118 const stored = { }
119119 for ( const m of messages ) {
120120 stored [ m . uri ] = true
@@ -157,29 +157,33 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
157157
158158 if ( options . thread ) { // only show things in thread
159159 if ( store . holds ( message , ns . sioc ( 'has_reply' ) , options . thread ) ) { // root of thread
160- debug . log ( ' addMessage: displaying root of thread ' + thread )
160+ // debug.log(' addMessage: displaying root of thread ' + thread)
161161 } else if ( thread && thread . sameTerm ( options . thread ) ) {
162- debug . log ( ' addMessage: Displaying body of thread ' + message . uri . slice ( - 10 ) )
162+ // debug.log(' addMessage: Displaying body of thread ' + message.uri.slice(-10))
163163 } else {
164- debug . log ( ' addMessage: Suppress non-thread message in thread table ' + message . uri . slice ( - 10 ) )
164+ // debug.log(' addMessage: Suppress non-thread message in thread table ' + message.uri.slice(-10))
165165 return // suppress message not in thread
166166 }
167167 } else { // Not threads
168168 if ( thread ) {
169- debug . log ( ' addMessage: Suppress thread message in non-thread table ' + message . uri . slice ( - 10 ) )
169+ // debug.log(' addMessage: Suppress thread message in non-thread table ' + message.uri.slice(-10))
170170 return // supress thread messages in body
171171 } else {
172- debug . log ( ' addMessage: Normal non-thread message in non-thread table ' + message . uri . slice ( - 10 ) )
172+ // debug.log(' addMessage: Normal non-thread message in non-thread table ' + message.uri.slice(-10))
173173 }
174174 }
175-
176- await insertMessageIntoTable ( channelObject ,
177- messageTable ,
178- message ,
179- messageTable . fresh ,
180- options ,
181- userContext
182- ) // fresh from elsewhere
175+ if ( ! messageTable . fresh ) { // if messageTable has been updated with insertMessageIntoTable() don't do it again
176+ // debug.log('@@@ infinite insertMessageIntoTable ' + message) // alain
177+ // debug.log('fresh ' + messageTable.fresh)
178+ // debug.log(messageTable)
179+ await insertMessageIntoTable ( channelObject ,
180+ messageTable ,
181+ message ,
182+ messageTable . fresh ,
183+ options ,
184+ userContext
185+ ) // fresh from elsewhere
186+ }
183187 }
184188
185189 /* Add a new messageTable at the top/bottom
@@ -194,16 +198,16 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
194198 if ( ! liveMessageTable ) await appendCurrentMessages ( ) // If necessary skip to today and add that
195199 return true // done
196200 }
197- debug . log ( ' insertPreviousMessages: loadPrevious given date ' + date )
201+ // debug.log(' insertPreviousMessages: loadPrevious given date ' + date)
198202
199203 date = await dateFolder . loadPrevious ( date , backwards ) // backwards
200- debug . log ( ' insertPreviousMessages: loadPrevious returns date ' + date )
204+ // debug.log(' insertPreviousMessages: loadPrevious returns date ' + date)
201205
202- debug . log (
206+ /* debug.log(
203207 `insertPreviousMessages: from ${
204208 backwards ? 'backwards' : 'forwards'
205209 } loadPrevious: ${date}`
206- )
210+ ) */
207211 if ( ! date && ! backwards && ! liveMessageTable ) {
208212 await appendCurrentMessages ( ) // If necessary skip to today and add that
209213 }
@@ -248,15 +252,15 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
248252 ** @returns DOM element generates
249253 */
250254 async function createMessageTable ( date , live ) {
251- debug . log ( ' createMessageTable for ' + date )
255+ // debug.log(' createMessageTable for ' + date)
252256 const chatDocument = dateFolder . leafDocumentFromDate ( date )
253257 try {
254- await store . fetcher . load ( chatDocument )
258+ await store . fetcher . createIfNotExists ( chatDocument )
255259 } catch ( err ) {
256260 const messageTable = dom . createElement ( 'table' )
257261 const statusTR = messageTable . appendChild ( dom . createElement ( 'tr' ) ) // ### find status in exception
258262 if ( err . response && err . response . status && err . response . status === 404 ) {
259- debug . log ( 'Error 404 for chat file ' + chatDocument )
263+ // debug.log('Error 404 for chat file ' + chatDocument)
260264 return await renderMessageTable ( date , live ) // no message file is fine. will be created later
261265 // statusTR.appendChild(widgets.errorMessageBlock(dom, 'no message file', 'white'))
262266 } else {
@@ -370,7 +374,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
370374 const userContext = { dom, statusArea, div: statusArea } // logged on state, pointers to user's stuff
371375
372376*/
373- debug . log ( 'Options for called message Area' , options )
377+ // debug.log('Options for called message Area', options)
374378 const messageTable = dom . createElement ( 'table' )
375379 messageTable . style . width = '100%' // fill the pane div
376380 messageTable . extendBackwards = extendBackwards // Make function available to scroll stuff
@@ -473,10 +477,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
473477 for ( const st of sts ) {
474478 await addMessage ( st . object , messageTable )
475479 }
476- messageTable . fresh = true
477-
478- // loadMessageTable(messageTable, chatDocument)
479- messageTable . fresh = false
480+ messageTable . fresh = true // message table updated with insertMessageIntoTable()
480481 return messageTable
481482 } // renderMessageTable
482483
@@ -576,7 +577,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
576577 }
577578 // debug.log(' chat/loadMoreWhereNeeded: Going now')
578579 const scrollBottom = div . scrollHeight - div . scrollTop
579- debug . log ( 'infinite scroll: adding above: top ' + div . scrollTop )
580+ // debug.log('infinite scroll: adding above: top ' + div.scrollTop)
580581 done = await earliest . messageTable . extendBackwards ( )
581582 if ( freeze ) {
582583 div . scrollTop = div . scrollHeight - scrollBottom
@@ -592,10 +593,10 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
592593 latest . messageTable . extendForwards
593594 ) {
594595 const scrollTop = div . scrollTop
595- debug . log (
596+ /* debug.log(
596597 'infinite scroll: adding below: bottom: ' +
597598 (div.scrollHeight - div.scrollTop - div.clientHeight)
598- )
599+ ) */
599600 done = await latest . messageTable . extendForwards ( ) // then add more data on the bottom
600601 if ( freeze ) {
601602 div . scrollTop = scrollTop // while adding below keep same things in view
@@ -689,7 +690,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
689690 const threadTime = store . any ( threadRootMessage , ns . dct ( 'created' ) , null , threadRootMessage . doc ( ) )
690691 if ( threadTime ) {
691692 earliest . limit = new Date ( threadTime . value )
692- debug . log ( ' inifinite : thread start at ' + earliest . limit )
693+ // debug.log(' infinite : thread start at ' + earliest.limit)
693694 }
694695 }
695696 }
0 commit comments