From faa129e7f4ea98df702141c334dc8e869c0ca673 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 27 Mar 2017 23:02:20 +0200 Subject: webclient: Fetch history, display times Still a bug though: when sending a message after history came in, all responses are delayed until after the next response. Need to investigate whether this is the client or the websocket relay --- webclient/client.html | 82 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 12 deletions(-) (limited to 'webclient') diff --git a/webclient/client.html b/webclient/client.html index 2305c17..7072ed1 100644 --- a/webclient/client.html +++ b/webclient/client.html @@ -24,7 +24,7 @@ function net_send(msg,cb){ net_callbacks[id]=cb; } -function fancysplit(text,freespace){ +function fancySplit(text,freespace){ var obj={ word: [], rest: [], @@ -50,6 +50,33 @@ function fancysplit(text,freespace){ return obj; } +function leftPad(str,num,chr){ + str=str+""; + if(str.length>=num)return str; + var pad=""; + while(pad.length=2){ @@ -178,16 +223,25 @@ function drawRoom(roomid){ function drawRoomEntry(type,args){ var tbody=document.getElementById("roomlog"); var tr=document.createElement("tr"); - var td1=document.createElement("td"),td2=document.createElement("td"); - var node1=document.createTextNode(""),node2=document.createTextNode(""); - td1.appendChild(node1); td2.appendChild(node2); - tr.appendChild(td1); tr.appendChild(td2); + var td0=document.createElement("td"); + var td1=document.createElement("td"); + var td2=document.createElement("td"); + var node0=document.createTextNode(formatTime(new Date())); + var node1=document.createTextNode(""); + var node2=document.createTextNode(""); + td0.appendChild(node0); + td1.appendChild(node1); + td2.appendChild(node2); + tr.appendChild(td0); + tr.appendChild(td1); + tr.appendChild(td2); tbody.appendChild(tr); switch(type){ case "message": tr.classList.add("message"); + node0.nodeValue=formatTime(new Date(args[1])); node1.nodeValue="<"+args[0]+">"; - node2.nodeValue=args[1]; + node2.nodeValue=args[2]; break; case "error": @@ -220,7 +274,7 @@ function addRoomEntry(roomid,type,args){ } function executeCommand(roomid,text){ - var spl=fancysplit(text,true); + var spl=fancySplit(text,true); if(spl.word.length==0)return; var cmd=spl.word[0]; var creds=null; @@ -258,7 +312,7 @@ function sendMessage(roomid,text){ var sentAs=username,msg=text.replace(/\n/g,""); net_send("send "+roomid+" "+msg,function(ok,err){ if(ok){ - addRoomEntry(roomid,"message",[sentAs,msg]); + addRoomEntry(roomid,"message",[sentAs,new Date().getTime(),msg]); return; } addRoomEntry(roomid,"error",["Unable to send message: "+err]); @@ -365,7 +419,11 @@ table{ width:100%; } #roomlog > tr > td:first-child{ - width:150px; + width:80px; + color:#666; +} +#roomlog > tr > td:nth-child(2){ + width:120px; padding-right:20px; text-align:right; } -- cgit v1.2.3-54-g00ecf