@@ -43,8 +43,8 @@ export function desktopNotification (str) {
4343/**
4444 * Renders a chat message inside a `messageTable`
4545 */
46- export function insertMessageIntoTable ( channelObject , messageTable , message , fresh , options , userContext ) {
47- const messageRow = renderMessageRow ( channelObject ,
46+ export async function insertMessageIntoTable ( channelObject , messageTable , message , fresh , options , userContext ) {
47+ const messageRow = await renderMessageRow ( channelObject ,
4848 message ,
4949 fresh ,
5050 options ,
@@ -105,7 +105,7 @@ export function insertMessageIntoTable (channelObject, messageTable, message, fr
105105export async function infiniteMessageArea ( dom , wasStore , chatChannel , options ) {
106106 // ///////////////////////////////////////////////////////////////////////
107107
108- function syncMessages ( chatChannel , messageTable ) {
108+ async function syncMessages ( chatChannel , messageTable ) {
109109 const displayed = { }
110110 let ele , ele2
111111 for ( ele = messageTable . firstChild ; ele ; ele = ele . nextSibling ) {
@@ -125,12 +125,12 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
125125 return st . object
126126 } )
127127 const stored = { }
128- messages . forEach ( function ( m ) {
129- stored [ m . uri ] = true
130- if ( ! displayed [ m . uri ] ) {
131- addMessage ( m , messageTable )
132- }
133- } )
128+ for ( const m of messages ) {
129+ stored [ m . uri ] = true
130+ if ( ! displayed [ m . uri ] ) {
131+ await addMessage ( m , messageTable )
132+ }
133+ }
134134
135135 // eslint-disable-next-line space-in-parens
136136 for ( ele = messageTable . firstChild ; ele ; ) {
@@ -149,28 +149,37 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
149149 } // syncMessages
150150
151151 // Called once per original message displayed
152- function addMessage ( message , messageTable ) {
153- const latest = mostRecentVersion ( message )
152+ async function addMessage ( message , messageTable ) {
153+ const latest = await mostRecentVersion ( message )
154154 // const content = store.any(latest, ns.sioc('content'))
155155 if ( isDeleted ( latest ) && ! options . showDeletedMessages ) {
156156 return // ignore deleted messaged -- @@ could also leave a placeholder
157157 }
158+ let thread = store . any ( null , ns . sioc ( 'has_member' ) , message , message . doc ( ) )
159+ const id = store . any ( message , ns . sioc ( 'id' ) , null , message . doc ( ) )
160+ if ( id && ! thread ) {
161+ thread = store . any ( null , ns . sioc ( 'has_member' ) , id , message . doc ( ) )
162+ }
163+
158164 if ( options . thread ) { // only show things in thread
159- const thread = store . any ( message , ns . sioc ( 'has_container' ) , null , message . doc ( ) )
160- if ( message . sameTerm ( options . thread ) ) {
161- // console.log(' displaying root of thread ' + thread)
162- } else if ( thread . sameTerm ( options . thread ) ) {
163- // console.log(' displaying body of thread ' + thread)
165+ if ( store . holds ( message , ns . sioc ( 'has_reply' ) , options . thread ) ) { // root of thread
166+ console . log ( ' addMessage: displaying root of thread ' + thread )
167+ } else if ( thread && thread . sameTerm ( options . thread ) ) {
168+ console . log ( ' addMessage: Displaying body of thread ' + + message . uri . slice ( - 10 ) )
164169 } else {
165- return // suppress message not in thread
170+ console . log ( ' addMessage: Suppress non-thread message in thread table ' + message . uri . slice ( - 10 ) )
171+ return // suppress message not in thread
166172 }
173+ } else { // Not threads
174+ if ( thread ) {
175+ console . log ( ' addMessage: Suppress thread message in non-thread table ' + message . uri . slice ( - 10 ) )
176+ return // supress thread messages in body
177+ } else {
178+ console . log ( ' addMessage: Normal non-thread message in non-thread table ' + message . uri . slice ( - 10 ) )
179+ }
167180 }
168181
169- // const replyTo = store.any(message, ns.sioc('reply_of'), null, message.doc())
170- // @@ best thing to do with a reply? Move to after the thing replied to and shift right?
171- // Sort by originalMessageDate, reply number?
172-
173- insertMessageIntoTable ( channelObject ,
182+ await insertMessageIntoTable ( channelObject ,
174183 messageTable ,
175184 message ,
176185 messageTable . fresh ,
@@ -244,20 +253,20 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
244253 const statusTR = messageTable . appendChild ( dom . createElement ( 'tr' ) ) // ### find status in exception
245254 if ( err . response && err . response . status && err . response . status === 404 ) {
246255 debug . log ( 'Error 404 for chat file ' + chatDocument )
247- return renderMessageTable ( date , live ) // no mssage file is fine.. will be craeted later
256+ return await renderMessageTable ( date , live ) // no mssage file is fine.. will be craeted later
248257 // statusTR.appendChild(widgets.errorMessageBlock(dom, 'no message file', 'white'))
249258 } else {
250259 debug . log ( '*** Error NON 404 for chat file ' + chatDocument )
251260 statusTR . appendChild ( widgets . errorMessageBlock ( dom , err , 'pink' ) )
252261 }
253262 return statusTR
254263 }
255- return renderMessageTable ( date , live )
264+ return await renderMessageTable ( date , live )
256265 }
257266
258- function renderMessageTable ( date , live ) {
259- let scrollBackbutton
260- let scrollForwardButton
267+ async function renderMessageTable ( date , live ) {
268+ const scrollBackbutton = null // was let
269+ const scrollForwardButton = null // was let
261270
262271 /// ///////////////// Scroll down adding more above
263272
@@ -311,6 +320,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
311320
312321 async function extendForwards ( ) {
313322 const done = await insertPreviousMessages ( false )
323+ /*
314324 if (done) {
315325 scrollForwardButton.firstChild.setAttribute(
316326 'src',
@@ -322,10 +332,12 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
322332 messageTable.extendedForwards = true
323333 }
324334 setScrollForwardButtonIcon()
335+ */
325336 return done
326337 }
327338
328339 function setScrollForwardButtonIcon ( ) {
340+ if ( ! scrollForwardButton ) return ;
329341 const sense = messageTable . extendedForwards ? ! newestFirst : newestFirst // noun_T-Block_1114657_000000.svg
330342 const scrollForwardIcon = messageTable . final
331343 ? 'noun_T-Block_1114657_000000.svg'
@@ -364,8 +376,9 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
364376 const userContext = { dom, statusArea, div: statusArea } // logged on state, pointers to user's stuff
365377
366378*/
379+ console . log ( 'Options for called message Area' , options )
367380 const messageTable = dom . createElement ( 'table' )
368-
381+ messageTable . style . width = "100%" // fill the pane div
369382 messageTable . extendBackwards = extendBackwards // Make function available to scroll stuff
370383 messageTable . extendForwards = extendForwards // Make function available to scroll stuff
371384
@@ -398,6 +411,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
398411 )
399412 // up traingles: noun_1369237.svg
400413 // down triangles: noun_1369241.svg
414+ /*
401415 const scrollBackIcon = newestFirst
402416 ? 'noun_1369241.svg'
403417 : 'noun_1369237.svg' // down and up arrows respoctively
@@ -411,7 +425,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
411425 messageTable.extendedBack = false
412426 scrollBackbuttonCell.appendChild(scrollBackbutton)
413427 setScrollBackbuttonIcon()
414-
428+ */
415429 const dateCell = scrollBackbuttonTR . appendChild ( dom . createElement ( 'td' ) )
416430 dateCell . style =
417431 'text-align: center; vertical-align: middle; color: #888; font-style: italic;'
@@ -421,6 +435,12 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
421435 const scrollForwardButtonCell = scrollBackbuttonTR . appendChild (
422436 dom . createElement ( 'td' )
423437 )
438+ if ( options . includeRemoveButton ) {
439+ scrollForwardButtonCell . appendChild ( widgets . cancelButton ( dom , _e => {
440+ div . parentNode . removeChild ( div )
441+ } ) )
442+ }
443+ /*
424444 const scrollForwardIcon = newestFirst
425445 ? 'noun_1369241.svg'
426446 : 'noun_1369237.svg' // down and up arrows respoctively
@@ -438,7 +458,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
438458 )
439459 messageTable.extendedForward = false
440460 setScrollForwardButtonIcon()
441-
461+ */
442462 messageTable . extendedForwards = false
443463
444464 if ( ! newestFirst ) {
@@ -455,9 +475,9 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
455475 // no need buttomns at the moment
456476 // messageTable.style.visibility = 'collapse' // Hide files with no messages
457477 }
458- sts . forEach ( st => {
459- addMessage ( st . object , messageTable )
460- } )
478+ for ( const st of sts ) {
479+ await addMessage ( st . object , messageTable )
480+ }
461481 messageTable . fresh = true
462482
463483 // loadMessageTable(messageTable, chatDocument)
@@ -526,7 +546,7 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
526546 div . refresh = async function ( ) {
527547 // only the last messageTable is live
528548 await addNewChatDocumentIfNewDay ( new Date ( ) )
529- syncMessages ( chatChannel , messageTable ) // @@ livemessagetable??
549+ await syncMessages ( chatChannel , messageTable ) // @@ livemessagetable??
530550 desktopNotification ( chatChannel )
531551 } // The short chat version the live update listening is done in the pane but we do it in the widget @@
532552 store . updater . addDownstreamChangeListener ( chatDocument , div . refresh ) // Live update
@@ -652,8 +672,6 @@ export async function infiniteMessageArea (dom, wasStore, chatChannel, options)
652672 const statusArea = div . appendChild ( dom . createElement ( 'div' ) )
653673 const userContext = { dom, statusArea, div : statusArea } // logged on state, pointers to user's stuff
654674
655- // const messageTable = dom.createElement('table') // @@ check does this go in renderMessageTable
656-
657675 let liveMessageTable
658676 const earliest = { messageTable : null } // Stuff about each end of the loaded days
659677 const latest = { messageTable : null }
0 commit comments