]> git.scottworley.com Git - reliable-chat/commitdiff
Timestamps for incoming messages
authorScott Worley <sworley@chkno.net>
Fri, 3 Aug 2012 07:45:01 +0000 (00:45 -0700)
committerScott Worley <sworley@chkno.net>
Fri, 3 Aug 2012 07:45:01 +0000 (00:45 -0700)
Plan: Outgoing messages will hang around at the bottom and have the
timestamp added when their echos come back from the servers.  This
will happen automatically when we start recalculating the timestamp
on each server arrival (part of switching from using first-timestamp
to median-timestamp).

webclient/rc.html

index 97491cdc885decba9854a7c0a0b000f55b56dae2..a062a176b2dc8a92e0bb7f62fee1ebf9cefa2d5a 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");
        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);
                var h = document.getElementById("history");
                h.appendChild(d);
                window.scrollTo(0, document.body.scrollHeight);
        function rcreceivemessages(server, messages) {
                for (var i in messages) {
                        var m = messages[i];
        function rcreceivemessages(server, messages) {
                for (var i in messages) {
                        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;
                        var seen_key = make_seen_key(m.ID, m.Text);
                        if (!(seen_key in seen)) {
                                seen[seen_key] = true;