]> git.scottworley.com Git - reliable-chat/blobdiff - webclient/rc.html
Pass message on *after* setting since.
[reliable-chat] / webclient / rc.html
index 8f69921f4241c678fc0d565045b6abb6699b882d..0dd591c11f3ac9c3a264ada813232136dd742a49 100644 (file)
                }
        }
 
+       function rcformattime(t) {
+               var d = t.getDay();
+               d = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][d];
+               var h = t.getHours();
+               var m = t.getMinutes();
+               var s = t.getSeconds();
+               function pad(x) {
+                       return (x < 10 ? "0" : "") + x;
+               }
+               return d + " " + pad(h) + ":" + pad(m) + ":" + pad(s);
+       }
+
        function rcaddmessagetohistory(message) {
                var d = document.createElement("div");
-               d.appendChild(document.createTextNode(message.Text));
+               var text = (message.Time ? rcformattime(message.Time) : "") + " " + message.Text;
+               d.appendChild(document.createTextNode(text));
                var h = document.getElementById("history");
                h.appendChild(d);
                window.scrollTo(0, document.body.scrollHeight);
 
        function rcreceivemessages(server, messages) {
                for (var i in messages) {
-                       var seen_key = make_seen_key(messages[i]['ID'], messages[i]['Text']);
+                       var m = messages[i];
+                       m.Time = new Date(m.Time);
+                       var seen_key = make_seen_key(m.ID, m.Text);
                        if (!(seen_key in seen)) {
                                seen[seen_key] = true;
-                               rcaddmessagetohistory(messages[i]);
+                               rcaddmessagetohistory(m);
                                for (var i in servers) {
                                        rcchangeserverstatus(servers[i], "sad");
                                }
                                        if (rtxt != null) {
                                                var messages = JSON.parse(rtxt);
                                                if (messages != null) {
-                                                       rcreceivemessages(server, messages);
                                                        delay = 40;
                                                        if (messages.length >= 1 && "Time" in messages[messages.length-1]) {
-                                                               since[server] = messages[messages.length-1]["Time"];
+                                                               since[server] = messages[messages.length-1].Time;
                                                        }
+                                                       rcreceivemessages(server, messages);
                                                }
                                        }
                                }