From 145852361d049d4d51e727f7f62f970418f2a34a Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Thu, 24 Oct 2013 02:14:29 +0700 Subject: PM on Home (initial) --- web/scripts3.js | 405 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) (limited to 'web/scripts3.js') diff --git a/web/scripts3.js b/web/scripts3.js index e1cc5952..9b16e33a 100644 --- a/web/scripts3.js +++ b/web/scripts3.js @@ -1,3 +1,406 @@ +var ws=null; +var currentPMUser=""; +var currentMID=0; + +/******************************************************************************/ + +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","#").attr("onclick","return showPM('"+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=$('