Skip to content

Commit f03a8be

Browse files
remove more src/ changes from this branch
1 parent 91df318 commit f03a8be

4 files changed

Lines changed: 72 additions & 106 deletions

File tree

src/chat/infinite.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Common code for a discussion are a of messages about something
22
// This version runs over a series of files for different time periods
33
//
4-
// Parameters for the whole chat like its title are stored on
4+
// Parameters for the whole chat like its title are stred on
55
// index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl
66
//
77
/* global alert $rdf */
@@ -165,12 +165,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
165165
// if (text) field.value = text No - don't destroy half-finsihed user input
166166

167167
sts.push(
168-
new $rdf.Statement(
169-
chatChannel,
170-
ns.wf('message'),
171-
message,
172-
chatDocument
173-
)
168+
new $rdf.Statement(chatChannel, ns.wf('message'), message, chatDocument)
174169
)
175170
sts.push(
176171
new $rdf.Statement(message, ns.sioc('content'), content, chatDocument)
@@ -209,7 +204,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
209204
) {
210205
console.log(
211206
'@@@ SERVER_MKDIRP_BUG: Should only happen once: create chat file: ' +
212-
chatDocument
207+
chatDocument
213208
)
214209
await createIfNotExists(chatDocument)
215210
}
@@ -365,7 +360,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
365360
})
366361

367362
// eslint-disable-next-line space-in-parens
368-
for (ele = messageTable.firstChild; ele;) {
363+
for (ele = messageTable.firstChild; ele; ) {
369364
ele2 = ele.nextSibling
370365
if (ele.AJAR_subject && !stored[ele.AJAR_subject.uri]) {
371366
messageTable.removeChild(ele)
@@ -407,7 +402,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
407402
date = await dateFolder.loadPrevious(date, backwards) // backwards
408403
console.log(
409404
`insertPreviousMessages: from ${
410-
backwards ? 'backwards' : 'forwards'
405+
backwards ? 'backwards' : 'forwards'
411406
} loadPrevious: ${date}`
412407
)
413408
if (!date && !backwards && !liveMessageTable) {
@@ -753,20 +748,6 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
753748
var latest = { messageTable: null }
754749

755750
var lock = false
756-
757-
function loadBackwardsMessages (magicZone) {
758-
return (div.scrollTop < magicZone &&
759-
earliest.messageTable &&
760-
!earliest.messageTable.initial &&
761-
earliest.messageTable.extendBackwards)
762-
}
763-
function loadForwardMessages (magicZone) {
764-
return (options.selectedMessage && // we started in the middle not at the bottom
765-
div.scrollHeight - div.scrollTop - div.clientHeight < magicZone && // we are scrolled right to the bottom
766-
latest.messageTable &&
767-
!latest.messageTable.final && // there is more data to come
768-
latest.messageTable.extendForwards)
769-
}
770751
async function loadMoreWhereNeeded (event, fixScroll) {
771752
if (lock) return
772753
lock = true
@@ -777,7 +758,10 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
777758
var done
778759

779760
while (
780-
loadBackwardsMessages(magicZone)
761+
div.scrollTop < magicZone &&
762+
earliest.messageTable &&
763+
!earliest.messageTable.initial &&
764+
earliest.messageTable.extendBackwards
781765
) {
782766
const scrollBottom = div.scrollHeight - div.scrollTop
783767
console.log('infinite scroll: adding above: top ' + div.scrollTop)
@@ -789,12 +773,16 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
789773
if (done) break
790774
}
791775
while (
792-
loadForwardMessages(magicZone)
776+
options.selectedMessage && // we started in the middle not at the bottom
777+
div.scrollHeight - div.scrollTop - div.clientHeight < magicZone && // we are scrolled right to the bottom
778+
latest.messageTable &&
779+
!latest.messageTable.final && // there is more data to come
780+
latest.messageTable.extendForwards
793781
) {
794782
const scrollTop = div.scrollTop
795783
console.log(
796784
'infinite scroll: adding below: bottom: ' +
797-
(div.scrollHeight - div.scrollTop - div.clientHeight)
785+
(div.scrollHeight - div.scrollTop - div.clientHeight)
798786
)
799787
done = await latest.messageTable.extendForwards() // then add more data on the bottom
800788
if (freeze) {

src/chat/message.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,7 @@ export function creatorAndDateHorizontal (td1, creator, date, message) {
9393
}
9494

9595
// BODY of renderMessage
96-
function shouldInsertBefore (dateString, ele, newestFirst) {
97-
return (
98-
(dateString > ele.AJAR_date && newestFirst) ||
99-
(dateString < ele.AJAR_date && !newestFirst)
100-
)
101-
}
102-
// not sure about this one...
103-
function processAuthorAboveContent (td1, creator) {
104-
const img = dom.createElement('img')
105-
img.setAttribute(
106-
'style',
107-
'max-height: 2.5em; max-width: 2.5em; border-radius: 0.5em; margin: auto;'
108-
)
109-
UI.widgets.setImage(img, creator)
110-
td1.appendChild(img)
111-
}
112-
function renderMessageContent () {}
96+
11397
export function renderMessage (
11498
messageTable,
11599
bindings,
@@ -143,7 +127,10 @@ export function renderMessage (
143127
break
144128
}
145129
var newestFirst = options.newestfirst === true
146-
if (shouldInsertBefore(dateString, ele, newestFirst)) {
130+
if (
131+
(dateString > ele.AJAR_date && newestFirst) ||
132+
(dateString < ele.AJAR_date && !newestFirst)
133+
) {
147134
messageTable.insertBefore(messageRow, ele)
148135
done = true
149136
break
@@ -156,7 +143,13 @@ export function renderMessage (
156143
var td1 = dom.createElement('td')
157144
messageRow.appendChild(td1)
158145
if (options.authorAboveContent) {
159-
processAuthorAboveContent(td1, creator)
146+
const img = dom.createElement('img')
147+
img.setAttribute(
148+
'style',
149+
'max-height: 2.5em; max-width: 2.5em; border-radius: 0.5em; margin: auto;'
150+
)
151+
UI.widgets.setImage(img, creator)
152+
td1.appendChild(img)
160153
} else {
161154
creatorAndDate(td1, creator, UI.widgets.shortDate(dateString), message)
162155
}

src/utils.js

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ function syncTableToArrayReOrdered (table, things, createNewRow) {
186186

187187
for (let g = 0; g < things.length; g++) {
188188
var thing = things[g]
189-
if (g >= table.children.length) {
190-
// table needs extending
189+
if (g >= table.children.length) { // table needs extending
191190
const newRow = createNewRow(thing)
192191
newRow.subject = thing
193192
table.appendChild(newRow)
@@ -413,13 +412,15 @@ function shortName (uri) {
413412
for (const ns in this.prefixes) {
414413
namespaces[this.prefixes[ns]] = ns // reverse index
415414
}
416-
415+
let pok
417416
const canUse = function canUse (pp) {
418417
// if (!__Serializer.prototype.validPrefix.test(pp)) return false; // bad format
419-
return pp === 'ns'
418+
if (pp === 'ns') return false // boring
420419
// if (pp in this.namespaces) return false; // already used
421420
// this.prefixes[uri] = pp;
422421
// this.namespaces[pp] = uri;
422+
pok = pp
423+
return true
423424
}
424425

425426
let i
@@ -434,14 +435,13 @@ function shortName (uri) {
434435
else break
435436
}
436437
p = p.slice(0, i)
437-
if (p.length < 6 && canUse(p)) {
438-
return p
439-
} else {
440-
for (let j = 0; j < 6; j++) {
441-
if (canUse(p.slice(0, j))) return p.slice(0, j)
442-
}
443-
}
444-
for (i = 0; ; i++) if (canUse(p.slice(0, 3) + i)) return p.slice(0, 3) + i
438+
if (p.length < 6 && canUse(p)) return pok // exact i sbest
439+
if (canUse(p.slice(0, 3))) return pok
440+
if (canUse(p.slice(0, 2))) return pok
441+
if (canUse(p.slice(0, 4))) return pok
442+
if (canUse(p.slice(0, 1))) return pok
443+
if (canUse(p.slice(0, 5))) return pok
444+
for (i = 0; ; i++) if (canUse(p.slice(0, 3) + i)) return pok
445445
}
446446
}
447447

@@ -499,59 +499,20 @@ function labelWithOntology (x, initialCap) {
499499
//
500500
// @returns string
501501
//
502-
503-
function decodeAsciiPoints (s) {
504-
for (var i = s.length - 3; i > 0; i--) {
505-
const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
506-
while (
507-
s[i] === '%' &&
508-
hex.indexOf(s[i + 1]) >= 0 &&
509-
hex.indexOf(s[i + 2]) >= 0
510-
) {
511-
s =
512-
s.slice(0, i) +
513-
String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) +
514-
s.slice(i + 3)
515-
}
516-
}
517-
return s
518-
}
519-
function trimS (s) {
520-
if (s.slice(-5) === '#this') s = s.slice(0, -5)
521-
else if (s.slice(-3) === '#me') s = s.slice(0, -3)
522-
// these were below the hash check. not sure if this makes a difference
523-
// but something to test to make sure
524-
if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
525-
else if (s.slice(-5) === '/foaf') s = s.slice(0, -5)
526-
return s
527-
}
528-
function getLab1 (x, kb) {
529-
return (
530-
kb.any(x, UI.ns.link('message')) ||
531-
kb.any(x, UI.ns.vcard('fn')) ||
532-
kb.any(x, UI.ns.foaf('name')) ||
533-
kb.any(x, UI.ns.dct('title')) ||
534-
kb.any(x, UI.ns.dc('title')) ||
535-
kb.any(x, UI.ns.rss('title')) ||
536-
kb.any(x, UI.ns.contact('fullName')) ||
537-
kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) ||
538-
kb.any(x, UI.ns.cal('summary')) ||
539-
kb.any(x, UI.ns.foaf('nick')) ||
540-
kb.any(x, UI.ns.rdfs('label'))
541-
)
542-
}
543502
function label (x, initialCap) {
544503
// x is an object
545504
function doCap (s) {
546505
// s = s.toString()
547-
return initialCap ? s.slice(0, 1).toUpperCase() + s.slice(1) : s
506+
if (initialCap) return s.slice(0, 1).toUpperCase() + s.slice(1)
507+
return s
548508
}
549509
function cleanUp (s1) {
550510
var s2 = ''
551511
if (s1.slice(-1) === '/') s1 = s1.slice(0, -1) // chop trailing slash
552512
for (var i = 0; i < s1.length; i++) {
553513
if (s1[i] === '_' || s1[i] === '-') {
554514
s2 += ' '
515+
continue
555516
}
556517
s2 += s1[i]
557518
if (
@@ -581,7 +542,18 @@ function label (x, initialCap) {
581542
// @@ TBD: Add subproperties of rdfs:label
582543

583544
var kb = UI.store
584-
var lab1 = getLab1(x, kb)
545+
var lab1 =
546+
kb.any(x, UI.ns.link('message')) ||
547+
kb.any(x, UI.ns.vcard('fn')) ||
548+
kb.any(x, UI.ns.foaf('name')) ||
549+
kb.any(x, UI.ns.dct('title')) ||
550+
kb.any(x, UI.ns.dc('title')) ||
551+
kb.any(x, UI.ns.rss('title')) ||
552+
kb.any(x, UI.ns.contact('fullName')) ||
553+
kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) ||
554+
kb.any(x, UI.ns.cal('summary')) ||
555+
kb.any(x, UI.ns.foaf('nick')) ||
556+
kb.any(x, UI.ns.rdfs('label'))
585557

586558
if (lab1) {
587559
return doCap(lab1.value)
@@ -607,15 +579,28 @@ function label (x, initialCap) {
607579
.join('/') // If it is properly encoded
608580
} catch (e) {
609581
// try individual decoding of ASCII code points
610-
s = decodeAsciiPoints(s)
582+
for (var i = s.length - 3; i > 0; i--) {
583+
const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
584+
while (
585+
s[i] === '%' &&
586+
hex.indexOf(s[i + 1]) >= 0 &&
587+
hex.indexOf(s[i + 2]) >= 0
588+
) {
589+
s =
590+
s.slice(0, i) +
591+
String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) +
592+
s.slice(i + 3)
593+
}
594+
}
611595
}
612-
s = trimS()
596+
if (s.slice(-5) === '#this') s = s.slice(0, -5)
597+
else if (s.slice(-3) === '#me') s = s.slice(0, -3)
613598

614599
var hash = s.indexOf('#')
615600
if (hash >= 0) return cleanUp(s.slice(hash + 1))
616601

617-
/* put this in trimS function if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
618-
else if (s.slice(-5) === '/foaf') s = s.slice(0, -5) */
602+
if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
603+
else if (s.slice(-5) === '/foaf') s = s.slice(0, -5)
619604

620605
// Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
621606
var slash = s.lastIndexOf('/', s.length - 2) // (len-2) excludes trailing slash

src/widgets/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ var widgets = Object.assign(
2828
)
2929

3030
module.exports = widgets
31-
// console.log('@@@ widgets: ', widgets)
31+
console.log('@@@ widgets: ', widgets)
3232

3333
// ends

0 commit comments

Comments
 (0)