33 * @packageDocumentation
44 */
55
6- /* global alert $rdf */
7- import DateFolder from './dateFolder'
6+ /* global alert */
7+ const $rdf = require ( 'rdflib' )
8+ const DateFolder = require ( './dateFolder' )
89
910// @@ trace20190428T1745
1011
@@ -140,6 +141,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
140141 return true
141142 }
142143*/
144+
143145 /* Form for a new message
144146 */
145147 function newMessageForm ( messageTable ) {
@@ -203,14 +205,15 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
203205 field . select ( )
204206 }
205207 }
208+
206209 if (
207210 SERVER_MKDIRP_BUG &&
208211 ( kb . fetcher . requested [ chatDocument . uri ] === undefined ||
209212 kb . fetcher . requested [ chatDocument . uri ] === 404 )
210213 ) {
211214 console . log (
212215 '@@@ SERVER_MKDIRP_BUG: Should only happen once: create chat file: ' +
213- chatDocument
216+ chatDocument
214217 )
215218 await createIfNotExists ( chatDocument )
216219 }
@@ -305,17 +308,20 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
305308
306309 const chatDocument = dateFolder . leafDocumentFromDate ( new Date ( ) )
307310 var imageDoc
311+
308312 function getImageDoc ( ) {
309313 imageDoc = kb . sym (
310314 chatDocument . dir ( ) . uri + 'Image_' + Date . now ( ) + '.png'
311315 )
312316 return imageDoc
313317 }
318+
314319 async function tookPicture ( imageDoc ) {
315320 if ( imageDoc ) {
316321 await sendMessage ( imageDoc . uri )
317322 }
318323 }
324+
319325 middle . appendChild (
320326 UI . media . cameraButton ( dom , kb , getImageDoc , tookPicture )
321327 )
@@ -366,7 +372,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
366372 } )
367373
368374 // eslint-disable-next-line space-in-parens
369- for ( ele = messageTable . firstChild ; ele ; ) {
375+ for ( ele = messageTable . firstChild ; ele ; ) {
370376 ele2 = ele . nextSibling
371377 if ( ele . AJAR_subject && ! stored [ ele . AJAR_subject . uri ] ) {
372378 messageTable . removeChild ( ele )
@@ -432,6 +438,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
432438 }
433439 return live // not done
434440 }
441+
435442 /* Remove message tables earlier than this one
436443 */
437444 function removePreviousMessages ( backwards , messageTable ) {
@@ -495,6 +502,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
495502 setScrollBackButtonIcon ( )
496503 return done
497504 }
505+
498506 function setScrollBackButtonIcon ( ) {
499507 const sense = messageTable . extendedBack ? ! newestFirst : newestFirst
500508 const scrollBackIcon = messageTable . initial
@@ -509,6 +517,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
509517 return sense ? 'noun_1369241.svg' : 'noun_1369237.svg'
510518 }
511519 }
520+
512521 async function scrollBackButtonHandler ( _event ) {
513522 if ( messageTable . extendedBack ) {
514523 removePreviousMessages ( true , messageTable )
@@ -536,6 +545,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
536545 setScrollForwardButtonIcon ( )
537546 return done
538547 }
548+
539549 function setScrollForwardButtonIcon ( ) {
540550 const sense = messageTable . extendedForwards ? ! newestFirst : newestFirst // noun_T-Block_1114657_000000.svg
541551 const scrollForwardIcon = messageTable . final
@@ -550,6 +560,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
550560 return ! sense ? 'noun_1369241.svg' : 'noun_1369237.svg'
551561 }
552562 }
563+
553564 async function scrollForwardButtonHandler ( _event ) {
554565 if ( messageTable . extendedForwards ) {
555566 removePreviousMessages ( false , messageTable )
@@ -702,6 +713,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
702713 }
703714 }
704715 }
716+
705717 /*
706718 function messageCount () {
707719 var n = 0
@@ -713,6 +725,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
713725 return n
714726 }
715727*/
728+
716729 /* Add the live message block with entry field for today
717730 */
718731 async function appendCurrentMessages ( ) {
@@ -754,6 +767,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
754767 var latest = { messageTable : null }
755768
756769 var lock = false
770+
757771 async function loadMoreWhereNeeded ( event , fixScroll ) {
758772 if ( lock ) return
759773 lock = true
@@ -788,7 +802,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
788802 const scrollTop = div . scrollTop
789803 console . log (
790804 'infinite scroll: adding below: bottom: ' +
791- ( div . scrollHeight - div . scrollTop - div . clientHeight )
805+ ( div . scrollHeight - div . scrollTop - div . clientHeight )
792806 )
793807 done = await latest . messageTable . extendForwards ( ) // then add more data on the bottom
794808 if ( freeze ) {
@@ -842,6 +856,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
842856 document . body . addEventListener ( 'scroll' , loadMoreWhereNeeded )
843857 }
844858 }
859+
845860 go ( )
846861 return div
847862}
0 commit comments