Skip to content

Commit eb3f708

Browse files
Make infiniteMessageArea async
1 parent 50aab68 commit eb3f708

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

__mocks__/rdflib.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ export class UpdateManager {
9191
onDone('uri', this.reportSuccess, 'body')
9292
return Promise.resolve()
9393
}
94+
95+
addDownstreamChangeListener () {
96+
}
9497
}

src/chat/infinite.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function desktopNotification (str) {
9595
* Parameters for the whole chat like its title are stored on
9696
* index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl
9797
*/
98-
export function infiniteMessageArea (dom, kb, chatChannel, options) {
98+
export async function infiniteMessageArea (dom, kb, chatChannel, options) {
9999
kb = kb || UI.store
100100
const ns = UI.ns
101101
const WF = $rdf.Namespace('http://www.w3.org/2005/01/wf/flow#')
@@ -491,11 +491,13 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
491491
async function extendBackwards () {
492492
const done = await insertPreviousMessages(true)
493493
if (done) {
494-
scrollBackButton.firstChild.setAttribute(
495-
'src',
496-
UI.icons.iconBase + 'noun_T-Block_1114655_000000.svg'
497-
) // T
498-
scrollBackButton.disabled = true
494+
if (scrollBackButton) {
495+
scrollBackButton.firstChild.setAttribute(
496+
'src',
497+
UI.icons.iconBase + 'noun_T-Block_1114655_000000.svg'
498+
) // T
499+
scrollBackButton.disabled = true
500+
}
499501
messageTable.initial = true
500502
} else {
501503
messageTable.extendedBack = true
@@ -505,6 +507,9 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
505507
}
506508

507509
function setScrollBackButtonIcon () {
510+
if (!scrollBackButton) {
511+
return
512+
}
508513
const sense = messageTable.extendedBack ? !newestFirst : newestFirst
509514
const scrollBackIcon = messageTable.initial
510515
? 'noun_T-Block_1114655_000000.svg'
@@ -576,7 +581,6 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
576581
/// ///////////////////////
577582

578583
var messageTable = dom.createElement('table')
579-
580584
messageTable.extendBackwards = extendBackwards // Make function available to scroll stuff
581585
messageTable.extendForwards = extendForwards // Make function available to scroll stuff
582586
// var messageButton
@@ -586,7 +590,6 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
586590

587591
messageTable.fresh = false
588592
messageTable.setAttribute('style', 'width: 100%;') // fill that div!
589-
590593
if (live) {
591594
messageTable.final = true
592595
liveMessageTable = messageTable
@@ -823,9 +826,11 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
823826
// During initial load ONLY keep scroll to selected thing or bottom
824827
function fixScroll () {
825828
if (options.selectedElement) {
826-
options.selectedElement.scrollIntoView({ block: 'center' }) // allign tops or bopttoms
829+
options.selectedElement.scrollIntoView({ block: 'center' }) // align tops or bottoms
827830
} else {
828-
liveMessageTable.inputRow.scrollIntoView(newestFirst) // allign tops or bopttoms
831+
if (liveMessageTable.inputRow.scrollIntoView) {
832+
liveMessageTable.inputRow.scrollIntoView(newestFirst) // align tops or bottoms
833+
}
829834
}
830835
}
831836

@@ -858,6 +863,6 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
858863
}
859864
}
860865

861-
go()
866+
await go()
862867
return div
863868
}

test/unit/chat/infinite.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { silenceDebugMessages } from '../../helpers/setup'
22
import { JSDOM } from 'jsdom'
33
import { infiniteMessageArea } from '../../../src/chat/infinite'
4-
import { graph, sym } from 'rdflib'
4+
import { sym } from 'rdflib'
55

66
silenceDebugMessages()
77
jest.mock('solid-auth-client')
@@ -11,13 +11,13 @@ describe('infiniteMessageArea', () => {
1111
it('exists', () => {
1212
expect(infiniteMessageArea).toBeInstanceOf(Function)
1313
})
14-
it('runs', () => {
15-
const kb = graph()
14+
it('runs', async () => {
15+
const kb = undefined // will default to UI.store
1616
const chatChannel = sym('https://domain.tld/chat')
1717
const options = {}
1818
;(window as any).alert = () => {}
1919

20-
const result = infiniteMessageArea(dom, kb, chatChannel, options)
20+
const result = await infiniteMessageArea(dom, kb, chatChannel, options)
2121
expect(result).toBeTruthy()
2222
})
2323
})

0 commit comments

Comments
 (0)