Fossil

Check-in [ebdd91b92f]
Login

Check-in [ebdd91b92f]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The ping=TCPPORT query parameter to /chat causes a call to /chat-ping on localhost and the given port whenever new chat content arrives. Can be used for notifications.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ebdd91b92fbff770d9457bcedd990453283763e5b70156eef2c5731ed90d7ca8
User & Date: drh 2020-12-24 15:10:38.587
Context
2020-12-24
15:57
Add the "fossil chat" command that attempts to bring up a chat window in the default web browser and provide alerts through the TTY. ... (check-in: f62805ed85 user: drh tags: trunk)
15:10
The ping=TCPPORT query parameter to /chat causes a call to /chat-ping on localhost and the given port whenever new chat content arrives. Can be used for notifications. ... (check-in: ebdd91b92f user: drh tags: trunk)
13:44
Hyperlink processing for chat messages is now handled on the server side, where we have knowledge of interwiki links, wiki page names, and valid artifact hashes. ... (check-in: 822653c269 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/chat.c.
70
71
72
73
74
75
76







77
78

79
80
81
82
83


84
85
86
87
88
89
90
** A value of 0.0 or less means that messages are retained forever.
*/

/*
** WEBPAGE: chat
**
** Start up a browser-based chat session.







*/
void chat_webpage(void){

  login_check_credentials();
  if( !g.perm.Chat ){
    login_needed(g.anon.Chat);
    return;
  }


  style_set_current_feature("chat");
  style_header("Chat");
  @ <style>
  @ #dialog {
  @  width: 97%%;
  @ }
  @ #chat-input-area {







>
>
>
>
>
>
>


>





>
>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
** A value of 0.0 or less means that messages are retained forever.
*/

/*
** WEBPAGE: chat
**
** Start up a browser-based chat session.
**
** This is the main page that humans use to access the chatroom.  Simply
** point a web-browser at /chat and the screen fills with the latest
** chat messages, and waits for new one.
**
** Other /chat-OP pages are used by XHR requests from this page to
** send new chat message, delete older messages, or poll for changes.
*/
void chat_webpage(void){
  int iPingTcp;
  login_check_credentials();
  if( !g.perm.Chat ){
    login_needed(g.anon.Chat);
    return;
  }
  iPingTcp = atoi(PD("ping","0"));
  if( iPingTcp<1000 || iPingTcp>65535 ) iPingTcp = 0;
  style_set_current_feature("chat");
  style_header("Chat");
  @ <style>
  @ #dialog {
  @  width: 97%%;
  @ }
  @ #chat-input-area {
167
168
169
170
171
172
173
174
175

176
177
178
179
180
181
182

  builtin_fossil_js_bundle_or("popupwidget", NULL);
  /* Always in-line the javascript for the chat page */
  @ <script nonce="%h(style_nonce())">/* chat.c:%d(__LINE__) */
  /* We need an onload handler to ensure that window.fossil is
     initialized before the chat init code runs. */
  @ window.addEventListener('load', function(){
  @ window.fossil.config.chatInitSize =
  @   %d(db_get_int("chat-initial-history",50));

  cgi_append_content(builtin_text("chat.js"),-1);
  @ }, false);
  @ </script>

  style_finish_page();
}








|

>







177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

  builtin_fossil_js_bundle_or("popupwidget", NULL);
  /* Always in-line the javascript for the chat page */
  @ <script nonce="%h(style_nonce())">/* chat.c:%d(__LINE__) */
  /* We need an onload handler to ensure that window.fossil is
     initialized before the chat init code runs. */
  @ window.addEventListener('load', function(){
  @ window.fossil.config.chatInitSize =\
  @   %d(db_get_int("chat-initial-history",50));
  @ window.fossil.config.pingTcp = %d(iPingTcp);
  cgi_append_content(builtin_text("chat.js"),-1);
  @ }, false);
  @ </script>

  style_finish_page();
}

530
531
532
533
534
535
536












    "DELETE FROM chat WHERE msgid=%d;\n"
    "INSERT INTO chat(mtime, xfrom, mdel)"
    " VALUES(julianday('now'), %Q, %d);\n"
    "COMMIT;",
    mdel, g.zLogin, mdel
  );
}



















>
>
>
>
>
>
>
>
>
>
>
>
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
    "DELETE FROM chat WHERE msgid=%d;\n"
    "INSERT INTO chat(mtime, xfrom, mdel)"
    " VALUES(julianday('now'), %Q, %d);\n"
    "COMMIT;",
    mdel, g.zLogin, mdel
  );
}

/*
** WEBPAGE: chat-ping
**
** HTTP requests coming to this page from a loopback IP address cause
** a single \007 (bel) character to be written on the controlling TTY.
** This is used to implement an audiable alert by local web clients.
*/
void chat_ping_webpage(void){
  const char *zIpAddr = PD("REMOTE_ADDR","nil");
  if( cgi_is_loopback(zIpAddr) ) fputc(7, stderr);
}
Changes to src/chat.js.
358
359
360
361
362
363
364



365
366
367
368
369
370
371
        //
        // Hence, even though innerHTML is normally frowned upon, it is
        // perfectly safe to use in this context.
        eContent.innerHTML += m.xmsg
      }
      eContent.classList.add('chat-message');
    }



  }
  async function poll(){
    if(poll.running) return;
    poll.running = true;
    fetch("chat-poll?name=" + Chat.mxMsg)
    .then(x=>x.json())
    .then(y=>newcontent(y))







>
>
>







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
        //
        // Hence, even though innerHTML is normally frowned upon, it is
        // perfectly safe to use in this context.
        eContent.innerHTML += m.xmsg
      }
      eContent.classList.add('chat-message');
    }
    if(i && window.fossil.config.pingTcp){
      fetch("http:/"+"/localhost:"+window.fossil.config.pingTcp+"/chat-ping");
    }
  }
  async function poll(){
    if(poll.running) return;
    poll.running = true;
    fetch("chat-poll?name=" + Chat.mxMsg)
    .then(x=>x.json())
    .then(y=>newcontent(y))