diff --git a/exec/load/json-chat.js b/exec/load/json-chat.js index a893d5e18b5ae6661db394af4f08ef4cb1c80109..d9976fd483e83640fff4e8f1d1ca2bdf7d4b639f 100644 --- a/exec/load/json-chat.js +++ b/exec/load/json-chat.js @@ -25,9 +25,9 @@ function JSONChat(usernum,jsonclient,host,port) { if(usernum > 0 && system.username(usernum)) usr = new User(usernum); if(usr) - this.nick = new Nick(usr.handle,system.name,usr.ip_address); + this.nick = new Nick(usr.alias,system.name,usr.ip_address); else if(user && user.number > 0) - this.nick = new Nick(user.handle,system.name,user.ip_address); + this.nick = new Nick(user.alias,system.name,user.ip_address); if(this.nick) this.client.subscribe("chat","channels." + this.nick.name + ".messages"); else @@ -88,25 +88,38 @@ function JSONChat(usernum,jsonclient,host,port) { /* pass any client update packets to this function to process inbound messages/status updates */ this.update = function(packet) { var arr = packet.location.split("."); - if(arr.shift().toUpperCase() != "CHAT") - return false; - var channel; var usr; - + var message; + while(arr.length > 0) { switch(arr.shift().toUpperCase()) { case "CHANNELS": channel = this.channels[arr[0].toUpperCase()]; break; case "MESSAGES": - channel.messages.push(packet.data); + message = packet.data; break; case "USERS": usr = channel.users[arr[0].toUpperCase()]; break; } } + + switch(packet.oper.toUpperCase()) { + case "SUBSCRIBE": + channel.messages.push(new Message("",packet.data.nick + " is here.",Date.now())); + break; + case "UNSUBSCRIBE": + channel.messages.push(new Message("",packet.data.nick + " has left.",Date.now())); + break; + case "WRITE": + channel.messages.push(message); + break; + default: + log(LOG_WARNING,"Unhandled response"); + break; + } return true; } @@ -152,7 +165,7 @@ function JSONChat(usernum,jsonclient,host,port) { case "WHO": var users = this.who(target); for(var u in users) - this.channels[target.toUpperCase()].messages.push(users[u]); + this.channels[target.toUpperCase()].users.push(users[u]); break; case "INVITE": break;