* Finally got room chat working properly. Just need to add the bells and whistles.
authorArt Cancro <ajc@citadel.org>
Sat, 24 Apr 2010 05:04:20 +0000 (05:04 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 24 Apr 2010 05:04:20 +0000 (05:04 +0000)
webcit/roomchat.c
webcit/static/t/roomchat.html
webcit/static/webcit.css

index 0933fa6168e1647a91300e3f57ff813306c73a5b..88ef6533a19d58d8f595a9a1544ea6b3bd055fd1 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #include "webcit.h"
-
+#include "webserver.h"
 
 /*
  * Display the screen containing multiuser chat for a room.
@@ -51,43 +51,14 @@ void do_chat(void)
 void chat_recv(void) {
        char buf[SIZ];
        char cl_user[SIZ];
-       char cl_text[SIZ];
-       int cl_text_len = 0;
-
-       begin_ajax_response();
 
        serv_printf("RCHT poll|%d", WC->last_chat_seq);
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                WC->last_chat_seq = extract_int(&buf[4], 0);
                extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user);
-               cl_text[0] = 0;
-               cl_text_len = 0;
-               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       safestrncpy(&cl_text[cl_text_len], buf, (sizeof(cl_text) - cl_text_len));
-                       cl_text_len += strlen(buf);
-               }
-
-               wc_printf("<div id=\"chat_seq_%d\">", WC->last_chat_seq);
-
-               if (strcasecmp(cl_user, WC->last_chat_user)) {
-                       wc_printf("<table border=0 width=100%% "
-                               "cellspacing=1 cellpadding=0 "
-                               "bgcolor=&quot;#ffffff&quot;>"
-                               "<tr><td></tr></td></table>"
-                       );
-
-               }
-
-               wc_printf("<table border=0 width=100%% cellspacing=0 cellpadding=0 "
-                       "bgcolor=&quot;#eeeeee&quot;>");
-
-               wc_printf("<tr><td>");
-
-               if (!strcasecmp(cl_user, ":")) {
-                       wc_printf("<I>");
-               }
 
+               /* who is speaking ... */
                if (strcasecmp(cl_user, WC->last_chat_user)) {
                        wc_printf("<B>");
 
@@ -97,27 +68,22 @@ void chat_recv(void) {
                        else {
                                wc_printf("<FONT COLOR=&quot;#0000FF&quot;>");
                        }
-                       jsescputs(cl_user);
+                       escputs(cl_user);
+                       strcpy(WC->last_chat_user, cl_user);
 
                        wc_printf("</FONT>: </B>");
                }
                else {
                        wc_printf("&nbsp;&nbsp;&nbsp;");
                }
-               jsescputs(cl_text);
-               if (!strcasecmp(cl_user, ":")) {
-                       wc_printf("</I>");
-               }
 
-               wc_printf("</TD></TR></TABLE>\n");
-               wc_printf("</div>\n");
+               /* what did they say ... */
+               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                       escputs(buf);
+               }
 
-               strcpy(WC->last_chat_user, cl_user);
-               /* FIXME make this work wc_printf("parent.chat_transcript.scrollTo(999999,999999);\">\n"); */
+               wc_printf("<br>\n");
        }
-
-       end_ajax_response();
-
 }
 
 
@@ -166,7 +132,7 @@ InitModule_ROOMCHAT
 (void)
 {
        WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0);
-       WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, 0);
+       WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, AJAX);
        WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0);
 }
 
index 87eefe009408fb9869d4141d60c6a2c6151d4b1f..e5de02af384651a4cabc0ed9b5a503263fceb764 100644 (file)
@@ -1,15 +1,12 @@
-<div id="chatrecv">
-This is the receiving side of the chat window, fee fie foe foo
+<div id="chatrecv_history" class="chatrecv_history">
 </div>
-<div id="chatsend">
+<div id="chatrecv" class="chatrecv">
+</div>
+<div id="chatsend" class="chatsend">
 <form method="POST" onsubmit="return chatsendfunc()" action="chat_send" id="chatsendid" name="chatsendform">
 <input type="hidden" name="nonce" value="<?NONCE>">
+<img src="static/citadelchat_16x.gif">
 <input type="text" size="80" maxlength="1024" id="send_this_id" name="send_this">
-<br />
-<input type="submit" name="send_button" value="<?_("Send")>">
-<input type="submit" name="help_button" value="<?_("Help")>">
-<input type="submit" name="list_button" value="<?_("List users")>">
-<input type="submit" name="exit_button" value="<?_("Exit")>">
 </div>
 
 <script type="text/javascript">
@@ -22,7 +19,13 @@ function chatsendfunc() {
 }
 
 new Ajax.PeriodicalUpdater('chatrecv', 'chat_recv', {
-       method: 'get', frequency: 2, insertion: 'bottom'
+       method: 'get', frequency: 2,
+               onSuccess: function(){ 
+                       $('chatrecv_history').innerHTML =
+                               $('chatrecv_history').innerHTML + $('chatrecv').innerHTML;
+                       $('chatrecv').innerHTML = '';
+                       $('chatrecv_history').scrollTop = 9999999;
+               }
 });
 
 </script>
index 0bd8bf79ba28a31b49167d1f962f08e268c4ee3a..9d1c4c0c4d8edb241a5d269b8b0798424266b144 100644 (file)
@@ -1613,3 +1613,23 @@ li.event_unread span, a.event_read_title {
        background-color: #FF0000;
        color: #FFFFFF;
 }
+
+.chatrecv_history {
+       margin-left: 5px;
+       margin-right: 5px;
+       margin-top: 5px;
+       margin-bottom: 5px;
+       height: 70%;
+       background-color: #FFFFFF;
+       overflow: auto;
+}
+
+.chatrecv {
+       display: none;
+}
+
+.chatsend {
+       width: 90%;
+       margin-left: auto;
+       margin-right: auto;
+}