Fossil SCM

Elide the chat-timeline-user's entries from /chat-search results. We would ideally elide those from the fts index altogether, but that name can be changed at any time and such a change would leave the fts update trigger out of sync.

stephan 2024-06-30 09:25 fts5-chat-search
Commit 1d64640ec753387b719a129399858312b5914f62ded24c6e7e13e0789000603f
+14 -6
--- src/chat.c
+++ src/chat.c
@@ -302,12 +302,10 @@
302302
/* We need an onload handler to ensure that window.fossil is
303303
initialized before the chat init code runs. */
304304
@ window.addEventListener('load', function(){
305305
@ document.body.classList.add('chat');
306306
@ /*^^^for skins which add their own BODY tag */;
307
- // ajax_emit_js_preview_modes(0);
308
- // chat_emit_alert_list();
309307
@ }, false);
310308
@ </script>
311309
312310
builtin_request_js("fossil.page.chatsearch.js");
313311
style_finish_page();
@@ -343,11 +341,11 @@
343341
}
344342
db_multi_exec("ALTER TABLE chat ADD COLUMN lmtime TEXT");
345343
}
346344
347345
if( !db_table_exists("repository", "chatfts1") ){
348
- db_multi_exec(
346
+ db_multi_exec(
349347
"CREATE VIRTUAL TABLE chatfts1 USING fts5("
350348
" xmsg, content=chat, content_rowid=msgid, tokenize=porter"
351349
");"
352350
"CREATE TRIGGER chat_ai AFTER INSERT ON chat BEGIN "
353351
" INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
@@ -790,20 +788,30 @@
790788
}
791789
chat_create_tables();
792790
cgi_set_content_type("application/json");
793791
794792
if( zQuery[0] ){
793
+ char *zChatRobot = db_get("chat-timeline-user", 0);
795794
iMax = db_int64(0, "SELECT max(msgid) FROM chat");
796795
iMin = db_int64(0, "SELECT min(msgid) FROM chat");
797796
blob_append_sql(&sql,
798797
"SELECT * FROM ("
799798
"SELECT c.msgid, datetime(c.mtime), c.xfrom, "
800
- " highlight(chatfts1, 0, '<span class=match>', '</span>'), "
799
+ " highlight(chatfts1, 0, '<span class=\"match\">', '</span>'), "
801800
" octet_length(c.file), c.fname, c.fmime, c.mdel, c.lmtime"
802
- " FROM chatfts1(%Q) f, chat c WHERE f.rowid=c.msgid "
801
+ " FROM chatfts1(%Q) f, chat c WHERE f.rowid=c.msgid ",
802
+ zQuery
803
+ );
804
+ if( zChatRobot!=0 ){
805
+ if( zChatRobot[0]!=0 ){
806
+ blob_append_sql(&sql, "AND c.xfrom IS NOT %Q ", zChatRobot);
807
+ }
808
+ fossil_free( zChatRobot );
809
+ }
810
+ blob_append_sql(&sql,
803811
" ORDER BY f.rowid DESC LIMIT %d"
804
- ") ORDER BY 1 ASC", zQuery, nLimit
812
+ ") ORDER BY 1 ASC", nLimit
805813
);
806814
}else{
807815
blob_append_sql(&sql,
808816
"SELECT msgid, datetime(mtime), xfrom, "
809817
" xmsg, octet_length(file), fname, fmime, mdel, lmtime"
810818
--- src/chat.c
+++ src/chat.c
@@ -302,12 +302,10 @@
302 /* We need an onload handler to ensure that window.fossil is
303 initialized before the chat init code runs. */
304 @ window.addEventListener('load', function(){
305 @ document.body.classList.add('chat');
306 @ /*^^^for skins which add their own BODY tag */;
307 // ajax_emit_js_preview_modes(0);
308 // chat_emit_alert_list();
309 @ }, false);
310 @ </script>
311
312 builtin_request_js("fossil.page.chatsearch.js");
313 style_finish_page();
@@ -343,11 +341,11 @@
343 }
344 db_multi_exec("ALTER TABLE chat ADD COLUMN lmtime TEXT");
345 }
346
347 if( !db_table_exists("repository", "chatfts1") ){
348 db_multi_exec(
349 "CREATE VIRTUAL TABLE chatfts1 USING fts5("
350 " xmsg, content=chat, content_rowid=msgid, tokenize=porter"
351 ");"
352 "CREATE TRIGGER chat_ai AFTER INSERT ON chat BEGIN "
353 " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
@@ -790,20 +788,30 @@
790 }
791 chat_create_tables();
792 cgi_set_content_type("application/json");
793
794 if( zQuery[0] ){
 
795 iMax = db_int64(0, "SELECT max(msgid) FROM chat");
796 iMin = db_int64(0, "SELECT min(msgid) FROM chat");
797 blob_append_sql(&sql,
798 "SELECT * FROM ("
799 "SELECT c.msgid, datetime(c.mtime), c.xfrom, "
800 " highlight(chatfts1, 0, '<span class=match>', '</span>'), "
801 " octet_length(c.file), c.fname, c.fmime, c.mdel, c.lmtime"
802 " FROM chatfts1(%Q) f, chat c WHERE f.rowid=c.msgid "
 
 
 
 
 
 
 
 
 
803 " ORDER BY f.rowid DESC LIMIT %d"
804 ") ORDER BY 1 ASC", zQuery, nLimit
805 );
806 }else{
807 blob_append_sql(&sql,
808 "SELECT msgid, datetime(mtime), xfrom, "
809 " xmsg, octet_length(file), fname, fmime, mdel, lmtime"
810
--- src/chat.c
+++ src/chat.c
@@ -302,12 +302,10 @@
302 /* We need an onload handler to ensure that window.fossil is
303 initialized before the chat init code runs. */
304 @ window.addEventListener('load', function(){
305 @ document.body.classList.add('chat');
306 @ /*^^^for skins which add their own BODY tag */;
 
 
307 @ }, false);
308 @ </script>
309
310 builtin_request_js("fossil.page.chatsearch.js");
311 style_finish_page();
@@ -343,11 +341,11 @@
341 }
342 db_multi_exec("ALTER TABLE chat ADD COLUMN lmtime TEXT");
343 }
344
345 if( !db_table_exists("repository", "chatfts1") ){
346 db_multi_exec(
347 "CREATE VIRTUAL TABLE chatfts1 USING fts5("
348 " xmsg, content=chat, content_rowid=msgid, tokenize=porter"
349 ");"
350 "CREATE TRIGGER chat_ai AFTER INSERT ON chat BEGIN "
351 " INSERT INTO chatfts1(rowid, xmsg) VALUES(new.msgid, new.xmsg);"
@@ -790,20 +788,30 @@
788 }
789 chat_create_tables();
790 cgi_set_content_type("application/json");
791
792 if( zQuery[0] ){
793 char *zChatRobot = db_get("chat-timeline-user", 0);
794 iMax = db_int64(0, "SELECT max(msgid) FROM chat");
795 iMin = db_int64(0, "SELECT min(msgid) FROM chat");
796 blob_append_sql(&sql,
797 "SELECT * FROM ("
798 "SELECT c.msgid, datetime(c.mtime), c.xfrom, "
799 " highlight(chatfts1, 0, '<span class=\"match\">', '</span>'), "
800 " octet_length(c.file), c.fname, c.fmime, c.mdel, c.lmtime"
801 " FROM chatfts1(%Q) f, chat c WHERE f.rowid=c.msgid ",
802 zQuery
803 );
804 if( zChatRobot!=0 ){
805 if( zChatRobot[0]!=0 ){
806 blob_append_sql(&sql, "AND c.xfrom IS NOT %Q ", zChatRobot);
807 }
808 fossil_free( zChatRobot );
809 }
810 blob_append_sql(&sql,
811 " ORDER BY f.rowid DESC LIMIT %d"
812 ") ORDER BY 1 ASC", nLimit
813 );
814 }else{
815 blob_append_sql(&sql,
816 "SELECT msgid, datetime(mtime), xfrom, "
817 " xmsg, octet_length(file), fname, fmime, mdel, lmtime"
818
--- src/fossil.page.chatsearch.js
+++ src/fossil.page.chatsearch.js
@@ -1,7 +1,7 @@
11
/*
2
-** This file contains the client-side implementation of fossil's
2
+** This file contains the client-side implementation of fossil's
33
** /chat-search application.
44
*/
55
window.fossil.onPageLoad(function(){
66
77
const F = window.fossil, D = F.dom;
@@ -112,11 +112,11 @@
112112
iframe.style.maxHeight = iframe.style.height
113113
= iframe.contentWindow.document.documentElement.scrollHeight + 'px';
114114
if(isHidden) D.addClass(iframe, 'hidden');
115115
}
116116
};
117
-
117
+
118118
cf.prototype = {
119119
scrollIntoView: function(){
120120
this.e.content.scrollIntoView();
121121
},
122122
setMessage: function(m){
@@ -388,11 +388,10 @@
388388
console.error(err);
389389
alert(err.toString());
390390
},
391391
392392
onload:function(jx){
393
-
394393
const firstChildOfBelow = e.below.firstChild;
395394
jx.msgs.forEach((m) => {
396395
var mw = new MessageWidget(m);
397396
if( bDown ){
398397
e.below.insertBefore(mw.e.body, firstChildOfBelow);
@@ -411,11 +410,11 @@
411410
ms.bIgnoreClick = false;
412411
}
413412
});
414413
}
415414
};
416
-
415
+
417416
return cf;
418417
})(); /* MessageSpacer */
419418
420419
/* This is called to submit a search - because the user clicked the
421420
** search button or pressed Enter in the input box.
@@ -470,11 +469,11 @@
470469
});
471470
}
472471
473472
/* Add event listeners to call submit_search() if the user presses Enter
474473
** or clicks the search button.
475
- */
474
+ */
476475
E1('#searchbutton').addEventListener('click', function(){
477476
submit_search();
478477
});
479478
E1('#textinput').addEventListener('keydown', function(ev){
480479
if( 13==ev.keyCode ){
481480
--- src/fossil.page.chatsearch.js
+++ src/fossil.page.chatsearch.js
@@ -1,7 +1,7 @@
1 /*
2 ** This file contains the client-side implementation of fossil's
3 ** /chat-search application.
4 */
5 window.fossil.onPageLoad(function(){
6
7 const F = window.fossil, D = F.dom;
@@ -112,11 +112,11 @@
112 iframe.style.maxHeight = iframe.style.height
113 = iframe.contentWindow.document.documentElement.scrollHeight + 'px';
114 if(isHidden) D.addClass(iframe, 'hidden');
115 }
116 };
117
118 cf.prototype = {
119 scrollIntoView: function(){
120 this.e.content.scrollIntoView();
121 },
122 setMessage: function(m){
@@ -388,11 +388,10 @@
388 console.error(err);
389 alert(err.toString());
390 },
391
392 onload:function(jx){
393
394 const firstChildOfBelow = e.below.firstChild;
395 jx.msgs.forEach((m) => {
396 var mw = new MessageWidget(m);
397 if( bDown ){
398 e.below.insertBefore(mw.e.body, firstChildOfBelow);
@@ -411,11 +410,11 @@
411 ms.bIgnoreClick = false;
412 }
413 });
414 }
415 };
416
417 return cf;
418 })(); /* MessageSpacer */
419
420 /* This is called to submit a search - because the user clicked the
421 ** search button or pressed Enter in the input box.
@@ -470,11 +469,11 @@
470 });
471 }
472
473 /* Add event listeners to call submit_search() if the user presses Enter
474 ** or clicks the search button.
475 */
476 E1('#searchbutton').addEventListener('click', function(){
477 submit_search();
478 });
479 E1('#textinput').addEventListener('keydown', function(ev){
480 if( 13==ev.keyCode ){
481
--- src/fossil.page.chatsearch.js
+++ src/fossil.page.chatsearch.js
@@ -1,7 +1,7 @@
1 /*
2 ** This file contains the client-side implementation of fossil's
3 ** /chat-search application.
4 */
5 window.fossil.onPageLoad(function(){
6
7 const F = window.fossil, D = F.dom;
@@ -112,11 +112,11 @@
112 iframe.style.maxHeight = iframe.style.height
113 = iframe.contentWindow.document.documentElement.scrollHeight + 'px';
114 if(isHidden) D.addClass(iframe, 'hidden');
115 }
116 };
117
118 cf.prototype = {
119 scrollIntoView: function(){
120 this.e.content.scrollIntoView();
121 },
122 setMessage: function(m){
@@ -388,11 +388,10 @@
388 console.error(err);
389 alert(err.toString());
390 },
391
392 onload:function(jx){
 
393 const firstChildOfBelow = e.below.firstChild;
394 jx.msgs.forEach((m) => {
395 var mw = new MessageWidget(m);
396 if( bDown ){
397 e.below.insertBefore(mw.e.body, firstChildOfBelow);
@@ -411,11 +410,11 @@
410 ms.bIgnoreClick = false;
411 }
412 });
413 }
414 };
415
416 return cf;
417 })(); /* MessageSpacer */
418
419 /* This is called to submit a search - because the user clicked the
420 ** search button or pressed Enter in the input box.
@@ -470,11 +469,11 @@
469 });
470 }
471
472 /* Add event listeners to call submit_search() if the user presses Enter
473 ** or clicks the search button.
474 */
475 E1('#searchbutton').addEventListener('click', function(){
476 submit_search();
477 });
478 E1('#textinput').addEventListener('keydown', function(ev){
479 if( 13==ev.keyCode ){
480

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button