Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add context-loading buttons to /chat search. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | fts5-chat-search |
| Files: | files | file ages | folders |
| SHA3-256: |
884214d0e3d6e0c54ba3f0127a67496f |
| User & Date: | stephan 2024-06-30 15:44:32.107 |
Context
|
2024-07-01
| ||
| 08:09 | Typo fix in /alerts help text. ... (check-in: 62a7616184 user: stephan tags: fts5-chat-search) | |
|
2024-06-30
| ||
| 15:44 | Add context-loading buttons to /chat search. ... (check-in: 884214d0e3 user: stephan tags: fts5-chat-search) | |
| 15:11 | Basic /chat search is working, but it's missing the load-more-context buttons and appropriate timestamps. Checking in for purposes of dogfooding it on my server. ... (check-in: 7561498cf7 user: stephan tags: fts5-chat-search) | |
Changes
Changes to src/chat.c.
| ︙ | ︙ | |||
242 243 244 245 246 247 248 |
@ </div>
@ <div id='chat-config' class='hidden chat-view'>
@ <div id='chat-config-options'></div>
/* ^^^populated client-side */
@ <div class='button-bar'><button class='action-close'>Close Settings</button></div>
@ </div>
@ <div id='chat-search' class='hidden chat-view'>
| < | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
@ </div>
@ <div id='chat-config' class='hidden chat-view'>
@ <div id='chat-config-options'></div>
/* ^^^populated client-side */
@ <div class='button-bar'><button class='action-close'>Close Settings</button></div>
@ </div>
@ <div id='chat-search' class='hidden chat-view'>
@ <div class='message-widget-content'></div>
/* ^^^populated client-side */
@ <div class='button-bar'><button class='action-close'>Close Search</button></div>
@ </div>
@ <div id='chat-messages-wrapper' class='chat-view'>
/* New chat messages get inserted immediately after this element */
@ <span id='message-inject-point'></span>
@ </div>
|
| ︙ | ︙ |
Changes to src/fossil.page.chat.js.
| ︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 |
const isHidden = iframe.classList.contains('hidden');
if(isHidden) D.removeClass(iframe, 'hidden');
iframe.style.maxHeight = iframe.style.height
= iframe.contentWindow.document.documentElement.scrollHeight + 'px';
if(isHidden) D.addClass(iframe, 'hidden');
}
};
| | | 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
const isHidden = iframe.classList.contains('hidden');
if(isHidden) D.removeClass(iframe, 'hidden');
iframe.style.maxHeight = iframe.style.height
= iframe.contentWindow.document.documentElement.scrollHeight + 'px';
if(isHidden) D.addClass(iframe, 'hidden');
}
};
cf.prototype = {
scrollIntoView: function(){
this.e.content.scrollIntoView();
},
setMessage: function(m){
const ds = this.e.body.dataset;
ds.timestamp = m.mtime;
|
| ︙ | ︙ | |||
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
const theMsg = findMessageWidgetParent(ev.target);
if(theMsg) f.popup.show(theMsg);
}/*_handleLegendClicked()*/
};
return cf;
})()/*MessageWidget*/;
const BlobXferState = (function(){
/* State for paste and drag/drop */
const bxs = {
dropDetails: document.querySelector('#chat-drop-details'),
blob: undefined,
clear: function(){
this.blob = undefined;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 |
const theMsg = findMessageWidgetParent(ev.target);
if(theMsg) f.popup.show(theMsg);
}/*_handleLegendClicked()*/
};
return cf;
})()/*MessageWidget*/;
/**
A widget for loading more messages (context) around a /chat-query
result message.
*/
Chat.SearchCtxLoader = (function(){
const nMsgContext = 5;
const zUpArrow = '\u25B2';
const zDownArrow = '\u25BC';
const cf = function(o){
/* iFirstInTable:
** msgid of first row in chatfts table.
**
** iLastInTable:
** msgid of last row in chatfts table.
**
** iPrevId:
** msgid of message immediately above this spacer. Or 0 if this
** spacer is above all results.
**
** iNextId:
** msgid of message immediately below this spacer. Or 0 if this
** spacer is below all results.
**
** bIgnoreClick:
** ignore any clicks if this is true. This is used to ensure there
** is only ever one request belonging to this widget outstanding
** at any time.
*/
this.o = {
iFirstInTable: o.first,
iLastInTable: o.last,
iPrevId: o.previd,
iNextId: o.nextid,
bIgnoreClick: false,
};
this.e = {
body: D.addClass(D.div(), 'spacer-widget'),
above: D.addClass(D.div(), 'spacer-widget-above'),
buttons: D.addClass(D.div(), 'spacer-widget-buttons'),
below: D.addClass(D.div(), 'spacer-widget-below'),
up: D.addClass(
D.button(zDownArrow+' Load '+nMsgContext+' more '+zDownArrow),
'up'
),
down: D.addClass(
D.button(zUpArrow+' Load '+nMsgContext+' more '+zUpArrow),
'down'
),
all: D.addClass(D.button('Load More'), 'all')
};
D.append(this.e.buttons, this.e.up, this.e.down, this.e.all);
D.append(this.e.body, this.e.above, this.e.buttons, this.e.below);
const ms = this;
this.e.up.addEventListener('click', ()=>ms.load_messages(false));
this.e.down.addEventListener('click', ()=>ms.load_messages(true));
this.e.all.addEventListener('click', ()=>ms.load_messages( (ms.o.iPrevId==0) ));
this.set_button_visibility();
};
cf.prototype = {
set_button_visibility: function() {
const o = this.o;
const iPrevId = (o.iPrevId!=0) ? o.iPrevId : o.iFirstInTable-1;
const iNextId = (o.iNextId!=0) ? o.iNextId : o.iLastInTable+1;
var nDiff = (iNextId - iPrevId) - 1;
D.addClass([this.e.up, this.e.down, this.e.all], 'hidden');
if( nDiff>0 ){
if( nDiff>nMsgContext && (o.iPrevId==0 || o.iNextId==0) ){
nDiff = nMsgContext;
}
if( nDiff<=nMsgContext && o.iPrevId!=0 && o.iNextId!=0 ){
D.removeClass(this.e.all, 'hidden');
this.e.all.innerText = (
zUpArrow + " Load " + nDiff + " more " + zDownArrow
);
}else{
if( o.iPrevId!=0 ) D.removeClass(this.e.up, 'hidden');
if( o.iNextId!=0 ) D.removeClass(this.e.down, 'hidden');
}
}
},
load_messages: function(bDown) {
if( this.bIgnoreClick ) return;
var iFirst = 0; /* msgid of first message to fetch */
var nFetch = 0; /* Number of messages to fetch */
var iEof = 0; /* last msgid in spacers range, plus 1 */
const e = this.e, o = this.o;
this.bIgnoreClick = true;
/* Figure out the required range of messages. */
if( bDown ){
iFirst = this.o.iNextId - nMsgContext;
if( iFirst<this.o.iFirstInTable ){
iFirst = this.o.iFirstInTable;
}
}else{
iFirst = this.o.iPrevId+1;
}
nFetch = nMsgContext;
iEof = (this.o.iNextId > 0) ? this.o.iNextId : this.o.iLastInTable+1;
if( iFirst+nFetch>iEof ){
nFetch = iEof - iFirst;
}
const ms = this;
F.fetch("chat-query",{
urlParams:{
q: '',
n: nFetch,
i: iFirst
},
responseType: "json",
onload:function(jx){
const firstChildOfBelow = e.below.firstChild;
jx.msgs.forEach((m) => {
var mw = new Chat.MessageWidget(m);
if( bDown ){
e.below.insertBefore(mw.e.body, firstChildOfBelow);
}else{
D.append(e.above, mw.e.body);
}
});
if( bDown ){
o.iNextId -= jx.msgs.length;
}else{
o.iPrevId += jx.msgs.length;
}
ms.set_button_visibility();
ms.bIgnoreClick = false;
}
});
}
};
return cf;
})() /*SearchCtxLoader*/;
const BlobXferState = (function(){
/* State for paste and drag/drop */
const bxs = {
dropDetails: document.querySelector('#chat-drop-details'),
blob: undefined,
clear: function(){
this.blob = undefined;
|
| ︙ | ︙ | |||
2171 2172 2173 2174 2175 2176 2177 |
Submits a history search using the main input field's current
text. It is assumed that Chat.e.viewSearch===Chat.e.currentView.
*/
Chat.submitSearch = function(){
const term = this.inputValue(true);
const eMsgTgt = D.clearElement(
this.e.viewSearch.querySelector('.message-widget-content')
| < > | | > > > > > > | | > > > > > > | | 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 |
Submits a history search using the main input field's current
text. It is assumed that Chat.e.viewSearch===Chat.e.currentView.
*/
Chat.submitSearch = function(){
const term = this.inputValue(true);
const eMsgTgt = D.clearElement(
this.e.viewSearch.querySelector('.message-widget-content')
)
if( !term ) return;
D.append( eMsgTgt, "Searching for ",term," ...");
F.fetch(
"chat-query", {
urlParams: {q: term},
responseType: 'json',
onload:function(jx){
let previd = 0;
console.log("jx =",jx);
D.clearElement(eMsgTgt);
jx.msgs.forEach((m)=>{
const mw = new Chat.MessageWidget(m);
const spacer = new Chat.SearchCtxLoader({
first: jx.first,
last: jx.last,
previd: previd,
nextid: m.msgid
});
D.append( eMsgTgt, spacer.e.body, mw.e.body );
previd = m.msgid;
});
if( jx.msgs.length ){
const spacer = new Chat.SearchCtxLoader({
first: jx.first,
last: jx.last,
previd: previd,
nextid: 0
});
D.append( eMsgTgt, spacer.e.body );
}else{
D.append( D.clearElement(eMsgTgt),
'No results matching the search term: ',
term );
}
}
}
|
| ︙ | ︙ |