Fossil SCM

/chat: added optional 'raw' URL argument to specify that the xmsg text should be returned as-is instead of HTML-izing it. This is not used by /chat but is to support Brad Harder's standalone curses-based /chat client (and similar ones).

stephan 2022-01-24 08:42 trunk
Commit 4359f4b573048e114094b07423c598538fdd3c4685ce28e3a5a89bf60f6f9b11
1 file changed +13 -3
+13 -3
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483483
** needs to take care to inject them at the end of the history rather
484484
** than the same place new messages go.
485485
**
486486
** If "before" is provided, "name" is ignored.
487487
**
488
+** If "raw" is provided, the "xmsg" text is sent back as-is, in
489
+** markdown format, rather than being HTML-ized. This is not used or
490
+** supported by fossil's own chat client but is intended for 3rd-party
491
+** clients. (Specifically, for Brad Harder's curses-based client.)
492
+**
488493
** The reply from this webpage is JSON that describes the new content.
489494
** Format of the json:
490495
**
491496
** | {
492497
** | "msgs":[
@@ -542,10 +547,11 @@
542547
const int iDelay = 1000; /* Delay until next poll (milliseconds) */
543548
int nDelay; /* Maximum delay.*/
544549
int msgid = atoi(PD("name","0"));
545550
const int msgBefore = atoi(PD("before","0"));
546551
int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
552
+ const int bRaw = P("raw")!=0;
547553
Blob sql = empty_blob;
548554
Stmt q1;
549555
nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
550556
login_check_credentials();
551557
if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
619625
blob_appendf(&json, "null,");
620626
}
621627
blob_appendf(&json, "\"uclr\":%!j,",
622628
user_color(zFrom ? zFrom : "nobody"));
623629
624
- zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
625
- blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
626
- fossil_free(zMsg);
630
+ if(bRaw){
631
+ blob_appendf(&json, "\"xmsg\":%!j,", zRawMsg);
632
+ }else{
633
+ zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
634
+ blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
635
+ fossil_free(zMsg);
636
+ }
627637
628638
if( nByte==0 ){
629639
blob_appendf(&json, "\"fsize\":0");
630640
}else{
631641
blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
632642
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483 ** needs to take care to inject them at the end of the history rather
484 ** than the same place new messages go.
485 **
486 ** If "before" is provided, "name" is ignored.
487 **
 
 
 
 
 
488 ** The reply from this webpage is JSON that describes the new content.
489 ** Format of the json:
490 **
491 ** | {
492 ** | "msgs":[
@@ -542,10 +547,11 @@
542 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
543 int nDelay; /* Maximum delay.*/
544 int msgid = atoi(PD("name","0"));
545 const int msgBefore = atoi(PD("before","0"));
546 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
 
547 Blob sql = empty_blob;
548 Stmt q1;
549 nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
550 login_check_credentials();
551 if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
619 blob_appendf(&json, "null,");
620 }
621 blob_appendf(&json, "\"uclr\":%!j,",
622 user_color(zFrom ? zFrom : "nobody"));
623
624 zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
625 blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
626 fossil_free(zMsg);
 
 
 
 
627
628 if( nByte==0 ){
629 blob_appendf(&json, "\"fsize\":0");
630 }else{
631 blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
632
--- src/chat.c
+++ src/chat.c
@@ -483,10 +483,15 @@
483 ** needs to take care to inject them at the end of the history rather
484 ** than the same place new messages go.
485 **
486 ** If "before" is provided, "name" is ignored.
487 **
488 ** If "raw" is provided, the "xmsg" text is sent back as-is, in
489 ** markdown format, rather than being HTML-ized. This is not used or
490 ** supported by fossil's own chat client but is intended for 3rd-party
491 ** clients. (Specifically, for Brad Harder's curses-based client.)
492 **
493 ** The reply from this webpage is JSON that describes the new content.
494 ** Format of the json:
495 **
496 ** | {
497 ** | "msgs":[
@@ -542,10 +547,11 @@
547 const int iDelay = 1000; /* Delay until next poll (milliseconds) */
548 int nDelay; /* Maximum delay.*/
549 int msgid = atoi(PD("name","0"));
550 const int msgBefore = atoi(PD("before","0"));
551 int nLimit = msgBefore>0 ? atoi(PD("n","0")) : 0;
552 const int bRaw = P("raw")!=0;
553 Blob sql = empty_blob;
554 Stmt q1;
555 nDelay = db_get_int("chat-poll-timeout",420); /* Default about 7 minutes */
556 login_check_credentials();
557 if( !g.perm.Chat ) {
@@ -619,13 +625,17 @@
625 blob_appendf(&json, "null,");
626 }
627 blob_appendf(&json, "\"uclr\":%!j,",
628 user_color(zFrom ? zFrom : "nobody"));
629
630 if(bRaw){
631 blob_appendf(&json, "\"xmsg\":%!j,", zRawMsg);
632 }else{
633 zMsg = chat_format_to_html(zRawMsg ? zRawMsg : "");
634 blob_appendf(&json, "\"xmsg\":%!j,", zMsg);
635 fossil_free(zMsg);
636 }
637
638 if( nByte==0 ){
639 blob_appendf(&json, "\"fsize\":0");
640 }else{
641 blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j",
642

Keyboard Shortcuts

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