Skip to content

Commit ef62741

Browse files
committed
Thread display is basically working
1 parent a3df52b commit ef62741

8 files changed

Lines changed: 337 additions & 214 deletions

File tree

package-lock.json

Lines changed: 200 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"mime-types": "^2.1.35",
6464
"npm": "^8.19.3",
6565
"pane-registry": "^2.4.13",
66-
"rdflib": "^2.2.21",
66+
"rdflib": "^2.2.26",
6767
"solid-logic": "^2.1.2",
6868
"solid-namespace": "^0.5.2",
6969
"uuid": "^8.3.2"

src/chat/bookmarks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @packageDocumentation
44
*/
55

6-
/* global alert confirm */
76
import * as debug from '../debug'
87
import { icons } from '../iconBase'
98
import { media } from '../media/index'
@@ -99,7 +98,8 @@ export async function findBookmarkDocument (userContext) {
9998
if (userContext.instances && userContext.instances.length > 0) {
10099
userContext.bookmarkDocument = userContext.instances[0]
101100
if (userContext.instances.length > 1) {
102-
alert('More than one bookmark file! ' + userContext.instances)
101+
console.warn('More than one bookmark file! ' + userContext.instances) // @@ todo - deal with > 1
102+
// Note should pick up community bookmarks as well
103103
}
104104
} else {
105105
if (userContext.publicProfile) {
@@ -111,7 +111,7 @@ export async function findBookmarkDocument (userContext) {
111111
debug.log('Creating new bookmark file ' + newBookmarkFile)
112112
await createIfNotExists(newBookmarkFile)
113113
} catch (e) {
114-
alert.error("Can't make fresh bookmark file:" + e)
114+
console.warn("Can't make fresh bookmark file:" + e)
115115
return userContext
116116
}
117117
await registerInTypeIndex(
@@ -121,7 +121,7 @@ export async function findBookmarkDocument (userContext) {
121121
)
122122
userContext.bookmarkDocument = newBookmarkFile
123123
} else {
124-
alert('You seem to have no bookmark file and not even a profile file.')
124+
console.warn('You seem to have no bookmark file and not even a profile file.')
125125
}
126126
}
127127
return userContext
@@ -164,7 +164,7 @@ async function addBookmark (context, target) {
164164
await updatePromise([], ins) // 20190118A
165165
} catch (e) {
166166
const msg = 'Making bookmark: ' + e
167-
alert.error(msg)
167+
console.warn(msg)
168168
return null
169169
}
170170
return bookmark
@@ -188,7 +188,7 @@ export async function toggleBookmark (userContext, target, bookmarkButton) {
188188
debug.log('Bookmark deleted: ' + bookmarks[i])
189189
} catch (e) {
190190
debug.error('Cant delete bookmark:' + e)
191-
alert('Cant delete bookmark:' + e)
191+
console.warn('Cant delete bookmark:' + e)
192192
}
193193
}
194194
} else {

src/chat/chatLogic.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,41 @@ export class ChatChannel {
8888
}
8989
} // class ChatChannel
9090

91-
export function originalVersion (message) {
91+
export async function allVersions (message) {
92+
let versions = [ message ]
93+
let m = message
94+
while (true) { // earlier?
95+
const prev = store.any(null, ns.dct('isReplacedBy'), m, m.doc())
96+
if (!prev) break
97+
await store.fetcher.load(prev)
98+
versions.unshift(prev)
99+
m = prev
100+
}
101+
m = message
102+
while (true) { // later?
103+
const next = store.any(m, ns.dct('isReplacedBy'), null, m.doc())
104+
if (!next) break
105+
versions.push(next)
106+
m = next
107+
}
108+
return versions
109+
}
110+
111+
export async function originalVersion (message) {
92112
let msg = message
93113
while (msg) {
94114
message = msg
95-
msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc())
115+
await store.fetcher.load(message)
116+
msg = store.any(null, ns.dct('isReplacedBy'), message, message.doc()) // @@@ may need to load doc
96117
}
97118
return message
98119
}
99120

100-
export function mostRecentVersion (message) {
121+
export async function mostRecentVersion (message) {
101122
let msg = message
102123
while (msg) {
103124
message = msg
125+
await store.fetcher.load(message)
104126
msg = store.any(message, ns.dct('isReplacedBy'), null, message.doc())
105127
}
106128
return message

src/chat/infinite.js

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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
105105
export 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

Comments
 (0)