var ws=null; var currentPMUser=""; var currentMID=0; /******************************************************************************/ function initPage() { var url=window.location.hash.substring(1); if(url.substr(0,5)==="chat/") { var uname=url.substr(5); showPM(uname); } } /******************************************************************************/ function initWS() { ws = new WebSocket("wss://ws.juick.com/?hash="+hash); ws.onopen = function() { $('#sidepanel').addClass('online'); }; ws.onclose = function() { $('#sidepanel').removeClass('online'); ws=null; initWS(); }; ws.onmessage = function(msg) { if(msg.data==' ') { ws.send(' '); } else { try { var jsonMsg=$.parseJSON(msg.data); if(jsonMsg.rid>0) { incomingComment(jsonMsg); } else if(jsonMsg.mid>0) { incomingPost(jsonMsg); } else { incomingPM(jsonMsg); } } catch(err) { console.log(err); } } }; setInterval(wsSendKeepAlive, 90000); } function wsSendKeepAlive() { if(ws!=null) { ws.send(' '); } } /******************************************************************************/ function initPMUList() { var ul=$('#pmulist'); ul.empty(); $.each(lastConversations,function(i,item) { var img=$("").attr("src","https://i.juick.com/as/"+item.uid+".png"); var a=$("").attr("href","#chat/"+item.uname); a.append(img).append(item.uname); if(item.MessagesCount) { a.append($("
").attr("class","unreadcnt").text(item.MessagesCount)); } var li=$("
  • ").append(a); ul.append(li); }); } /******************************************************************************/ function incomingPost(msg) { console.log(msg); if(groups[0].MessagesCount>0) { groups[0].MessagesCount++; } else { groups[0].MessagesCount=1; } initGroupsList(); } function incomingComment(msg) { console.log(msg); } function showGroup(gid) { currentPMUser=""; currentMID=0; groups[0].MessagesCount=0; initGroupsList(); $.getJSON('https://api.juick.com/home?hash='+hash+'&callback=?').done(function(data) { var ul=$('