Fossil SCM

Use the chat-timeline-user setting when formatting results for chat searches.

dan 2024-07-09 17:30 trunk
Commit 02349c875d62f7016436ca8f3a52627a3d10d43da77039b018ed43921708c0a9
1 file changed +22 -5
+22 -5
--- src/chat.c
+++ src/chat.c
@@ -511,19 +511,38 @@
511511
fossil_free(zOut);
512512
}
513513
}
514514
515515
/*
516
+** The SQL statement passed as the first argument should return zero or
517
+** more rows of data, each of which represents a single message from the
518
+** "chat" table. The rows returned should be similar to those returned
519
+** by:
520
+**
521
+** SELECT msgid,
522
+** datetime(mtime),
523
+** xfrom,
524
+** xmsg,
525
+** octet_length(file),"
526
+** fname,
527
+** fmime,
528
+** mdel,
529
+** lmtime
530
+** FROM chat;
516531
**
532
+** This function loops through all rows returned by statement p, adding
533
+** a record to the JSON stored in argument pJson for each. See comments
534
+** above function chat_poll_webpage() for a description of the JSON records
535
+** added to pJson.
517536
*/
518537
static int chat_poll_rowstojson(
519538
Stmt *p, /* Statement to read rows from */
520
- const char *zChatUser, /* Current user */
521539
int bRaw, /* True to return raw format xmsg */
522540
Blob *pJson /* Append json array entries here */
523541
){
524542
int cnt = 0;
543
+ const char *zChatUser = db_get("chat-timeline-user",0);
525544
while( db_step(p)==SQLITE_ROW ){
526545
int isWiki = 0; /* True if chat message is x-fossil-wiki */
527546
int id = db_column_int(p, 0);
528547
const char *zDate = db_column_text(p, 1);
529548
const char *zFrom = db_column_text(p, 2);
@@ -675,11 +694,10 @@
675694
void chat_poll_webpage(void){
676695
Blob json; /* The json to be constructed and returned */
677696
sqlite3_int64 dataVersion; /* Data version. Used for polling. */
678697
const int iDelay = 1000; /* Delay until next poll (milliseconds) */
679698
int nDelay; /* Maximum delay.*/
680
- const char *zChatUser; /* chat-timeline-user */
681699
int msgid = atoi(PD("name","0"));
682700
const int msgBefore = atoi(PD("before","0"));
683701
int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
684702
const int bRaw = P("raw")!=0;
685703
@@ -689,11 +707,10 @@
689707
login_check_credentials();
690708
if( !g.perm.Chat ) {
691709
chat_emit_permissions_error(1);
692710
return;
693711
}
694
- zChatUser = db_get("chat-timeline-user",0);
695712
chat_create_tables();
696713
cgi_set_content_type("application/json");
697714
dataVersion = db_int64(0, "PRAGMA data_version");
698715
blob_append_sql(&sql,
699716
"SELECT msgid, datetime(mtime), xfrom, xmsg, octet_length(file),"
@@ -729,11 +746,11 @@
729746
}
730747
db_prepare(&q1, "%s", blob_sql_text(&sql));
731748
blob_reset(&sql);
732749
blob_init(&json, "{\"msgs\":[\n", -1);
733750
while( nDelay>0 ){
734
- int cnt = chat_poll_rowstojson(&q1, zChatUser, bRaw, &json);
751
+ int cnt = chat_poll_rowstojson(&q1, bRaw, &json);
735752
if( cnt || msgBefore>0 ){
736753
break;
737754
}
738755
sqlite3_sleep(iDelay); nDelay--;
739756
while( nDelay>0 ){
@@ -809,11 +826,11 @@
809826
}
810827
811828
db_prepare(&q1, "%s", blob_sql_text(&sql));
812829
blob_reset(&sql);
813830
blob_init(&json, "{\"msgs\":[\n", -1);
814
- chat_poll_rowstojson(&q1, "", 0, &json);
831
+ chat_poll_rowstojson(&q1, 0, &json);
815832
db_finalize(&q1);
816833
blob_appendf(&json, "\n], \"first\":%lld, \"last\":%lld}", iMin, iMax);
817834
cgi_set_content(&json);
818835
return;
819836
}
820837
--- src/chat.c
+++ src/chat.c
@@ -511,19 +511,38 @@
511 fossil_free(zOut);
512 }
513 }
514
515 /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516 **
 
 
 
 
517 */
518 static int chat_poll_rowstojson(
519 Stmt *p, /* Statement to read rows from */
520 const char *zChatUser, /* Current user */
521 int bRaw, /* True to return raw format xmsg */
522 Blob *pJson /* Append json array entries here */
523 ){
524 int cnt = 0;
 
525 while( db_step(p)==SQLITE_ROW ){
526 int isWiki = 0; /* True if chat message is x-fossil-wiki */
527 int id = db_column_int(p, 0);
528 const char *zDate = db_column_text(p, 1);
529 const char *zFrom = db_column_text(p, 2);
@@ -675,11 +694,10 @@
675 void chat_poll_webpage(void){
676 Blob json; /* The json to be constructed and returned */
677 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
678 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
679 int nDelay; /* Maximum delay.*/
680 const char *zChatUser; /* chat-timeline-user */
681 int msgid = atoi(PD("name","0"));
682 const int msgBefore = atoi(PD("before","0"));
683 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
684 const int bRaw = P("raw")!=0;
685
@@ -689,11 +707,10 @@
689 login_check_credentials();
690 if( !g.perm.Chat ) {
691 chat_emit_permissions_error(1);
692 return;
693 }
694 zChatUser = db_get("chat-timeline-user",0);
695 chat_create_tables();
696 cgi_set_content_type("application/json");
697 dataVersion = db_int64(0, "PRAGMA data_version");
698 blob_append_sql(&sql,
699 "SELECT msgid, datetime(mtime), xfrom, xmsg, octet_length(file),"
@@ -729,11 +746,11 @@
729 }
730 db_prepare(&q1, "%s", blob_sql_text(&sql));
731 blob_reset(&sql);
732 blob_init(&json, "{\"msgs\":[\n", -1);
733 while( nDelay>0 ){
734 int cnt = chat_poll_rowstojson(&q1, zChatUser, bRaw, &json);
735 if( cnt || msgBefore>0 ){
736 break;
737 }
738 sqlite3_sleep(iDelay); nDelay--;
739 while( nDelay>0 ){
@@ -809,11 +826,11 @@
809 }
810
811 db_prepare(&q1, "%s", blob_sql_text(&sql));
812 blob_reset(&sql);
813 blob_init(&json, "{\"msgs\":[\n", -1);
814 chat_poll_rowstojson(&q1, "", 0, &json);
815 db_finalize(&q1);
816 blob_appendf(&json, "\n], \"first\":%lld, \"last\":%lld}", iMin, iMax);
817 cgi_set_content(&json);
818 return;
819 }
820
--- src/chat.c
+++ src/chat.c
@@ -511,19 +511,38 @@
511 fossil_free(zOut);
512 }
513 }
514
515 /*
516 ** The SQL statement passed as the first argument should return zero or
517 ** more rows of data, each of which represents a single message from the
518 ** "chat" table. The rows returned should be similar to those returned
519 ** by:
520 **
521 ** SELECT msgid,
522 ** datetime(mtime),
523 ** xfrom,
524 ** xmsg,
525 ** octet_length(file),"
526 ** fname,
527 ** fmime,
528 ** mdel,
529 ** lmtime
530 ** FROM chat;
531 **
532 ** This function loops through all rows returned by statement p, adding
533 ** a record to the JSON stored in argument pJson for each. See comments
534 ** above function chat_poll_webpage() for a description of the JSON records
535 ** added to pJson.
536 */
537 static int chat_poll_rowstojson(
538 Stmt *p, /* Statement to read rows from */
 
539 int bRaw, /* True to return raw format xmsg */
540 Blob *pJson /* Append json array entries here */
541 ){
542 int cnt = 0;
543 const char *zChatUser = db_get("chat-timeline-user",0);
544 while( db_step(p)==SQLITE_ROW ){
545 int isWiki = 0; /* True if chat message is x-fossil-wiki */
546 int id = db_column_int(p, 0);
547 const char *zDate = db_column_text(p, 1);
548 const char *zFrom = db_column_text(p, 2);
@@ -675,11 +694,10 @@
694 void chat_poll_webpage(void){
695 Blob json; /* The json to be constructed and returned */
696 sqlite3_int64 dataVersion; /* Data version. Used for polling. */
697 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
698 int nDelay; /* Maximum delay.*/
 
699 int msgid = atoi(PD("name","0"));
700 const int msgBefore = atoi(PD("before","0"));
701 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
702 const int bRaw = P("raw")!=0;
703
@@ -689,11 +707,10 @@
707 login_check_credentials();
708 if( !g.perm.Chat ) {
709 chat_emit_permissions_error(1);
710 return;
711 }
 
712 chat_create_tables();
713 cgi_set_content_type("application/json");
714 dataVersion = db_int64(0, "PRAGMA data_version");
715 blob_append_sql(&sql,
716 "SELECT msgid, datetime(mtime), xfrom, xmsg, octet_length(file),"
@@ -729,11 +746,11 @@
746 }
747 db_prepare(&q1, "%s", blob_sql_text(&sql));
748 blob_reset(&sql);
749 blob_init(&json, "{\"msgs\":[\n", -1);
750 while( nDelay>0 ){
751 int cnt = chat_poll_rowstojson(&q1, bRaw, &json);
752 if( cnt || msgBefore>0 ){
753 break;
754 }
755 sqlite3_sleep(iDelay); nDelay--;
756 while( nDelay>0 ){
@@ -809,11 +826,11 @@
826 }
827
828 db_prepare(&q1, "%s", blob_sql_text(&sql));
829 blob_reset(&sql);
830 blob_init(&json, "{\"msgs\":[\n", -1);
831 chat_poll_rowstojson(&q1, 0, &json);
832 db_finalize(&q1);
833 blob_appendf(&json, "\n], \"first\":%lld, \"last\":%lld}", iMin, iMax);
834 cgi_set_content(&json);
835 return;
836 }
837

Keyboard Shortcuts

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