Skip to content

Commit c64aa1f

Browse files
author
Tim Berners-Lee
committed
Fix bug mesages leaking into wrong day
1 parent fee03fb commit c64aa1f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/infiniteMessageArea.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ module.exports = function (dom, kb, subject, options) {
195195
displayed[ele.AJAR_subject.uri] = true
196196
}
197197
}
198-
var messages = kb.each(about, ns.wf('message'))
198+
199+
var messages = kb.statementsMatching(
200+
about, ns.wf('message'), null, messageTable.chatDocument).map( st => { return st.object})
199201
var stored = {}
200202
messages.map(function (m) {
201203
stored[m.uri] = true
@@ -364,6 +366,7 @@ module.exports = function (dom, kb, subject, options) {
364366
var messageTable = dom.createElement('table')
365367
messageTable.date = date
366368
var chatDocument = chatDocumentFromDate(date)
369+
messageTable.chatDocument = chatDocument
367370

368371
messageTable.fresh = false
369372
messageTable.setAttribute('style', 'width: 100%;') // fill that div!
@@ -423,9 +426,18 @@ module.exports = function (dom, kb, subject, options) {
423426
function addNewTableIfNeeded () {
424427
let now = new Date()
425428
let newChatDocument = chatDocumentFromDate(now)
426-
if (!newChatDocument.sameTerm(chatDocument)) {
429+
if (!newChatDocument.sameTerm(chatDocument)) { // It is a new day
430+
var oldChatDocument = chatDocument
427431
appendCurrentMessages()
428-
// @@ How to ping other clients and let them add one too? Add link to old message file?
432+
// Adding a link in the document will ping listeners to add the new block too
433+
if (!kb.holds(oldChatDocument, ns.rdfs('seeAlso'), newChatDocument, oldChatDocument)) {
434+
let sts = [ $rdf.st(oldChatDocument, ns.rdfs('seeAlso'), newChatDocument, oldChatDocument)]
435+
updater.update([], sts, function (ok, body) {
436+
if (!ok) {
437+
alert('Unable to link old message block to new one.' + body)
438+
}
439+
})
440+
}
429441
}
430442
return now
431443
}
@@ -439,8 +451,9 @@ module.exports = function (dom, kb, subject, options) {
439451
div.refresh = function () { // only the last messageTable is live
440452
addNewTableIfNeeded()
441453
syncMessages(subject, messageTable)
442-
}// The short chat version fors live update in the pane but we do it in the widget
454+
} // The short chat version fors live update in the pane but we do it in the widget
443455
kb.updater.addDownstreamChangeListener(chatDocument, div.refresh) // Live update
456+
// @@ Remove listener from previous table as it is now static
444457
}, err => {
445458
div.appendChild(UI.widgets.errorMessageBlock(
446459
dom, 'Problem accessing chat log file: ' + err))

0 commit comments

Comments
 (0)