Commit e9598473 authored by mcmlxxix's avatar mcmlxxix
Browse files

use chat.colors instead of chat.settings for attribute settings, use array...

use chat.colors instead of chat.settings for attribute settings, use array slice(-1 * chat.settings.MAX_HISTORY) to retrieve message history
parent d93afcb4
......@@ -3,19 +3,30 @@ if(!js.global.JSONClient)
function JSONChat(usernum,jsonclient,host,port) {
this.nick;
this.channels = {};
this.client = jsonclient;
this.chatView = undefined;
this.userView = undefined;
this.settings = {
var colors = {
NICK_COLOR:GREEN,
TEXT_COLOR:LIGHTGRAY,
PRIV_COLOR:RED,
ACTION_COLOR:LIGHTGREEN,
NOTICE_COLOR:BROWN
}
var settings = {
MAX_HISTORY:20
};
this.nick;
this.channels = {};
this.client = jsonclient;
this.chatView = undefined;
this.userView = undefined;
this.__defineGetter__("colors",function() {
return colors;
});
this.__defineGetter__("settings",function() {
return settings;
});
if(!this.client) {
if(!host || isNaN(port))
throw("invalid client arguments");
......@@ -74,7 +85,8 @@ function JSONChat(usernum,jsonclient,host,port) {
this.join = function(target,str) {
this.client.subscribe("chat","channels." + target + ".messages");
this.channels[target.toUpperCase()] = new Channel(target);
var history = this.client.read("chat","channels." + target + ".history",1);
var index = (-1 * this.settings.MAX_HISTORY);
var history = this.client.slice("chat","channels." + target + ".history",index,undefined,1);
var msgcount = 0;
var lastMsg = 0;
for each(var m in history) {
......@@ -104,17 +116,15 @@ function JSONChat(usernum,jsonclient,host,port) {
this.who = function(target) {
var chan = this.channels[target.toUpperCase()];
var users = this.client.who("chat","channels." + chan.name + ".messages");
if(chan)
chan.users = users;
chan.users = getUserList(this,chan);
if(this.userView)
updateUserView(this.userView,chan);
var uList=[];
for(var u in users) {
uList.push(users[u].nick);
for(var u in chan.users) {
uList.push(chan.users[u].nick);
}
chan.messages.push(new Message(undefined,"Users in " + chan.name + ": " + uList.join(", "),Date.now()));
return users;
return chan.users;
}
this.disconnect = function() {
......@@ -148,11 +158,11 @@ function JSONChat(usernum,jsonclient,host,port) {
switch(packet.oper.toUpperCase()) {
case "SUBSCRIBE":
channel.messages.push(new Message("",packet.data.nick + " is here.",Date.now()));
this.who(channel.name);
channel.users = getUserList(this,channel);
break;
case "UNSUBSCRIBE":
channel.messages.push(new Message("",packet.data.nick + " has left.",Date.now()));
this.who(channel.name);
channel.users = getUserList(this,channel);
break;
case "WRITE":
channel.messages.push(message);
......@@ -276,6 +286,11 @@ function JSONChat(usernum,jsonclient,host,port) {
this.time = time;
}
/* retrieve user list */
function getUserList(chat,chan) {
return chat.client.who("chat","channels." + chan.name + ".messages");
}
/* adapter for updating chat layout view */
function syncChatView(view,chat) {
for each(var c in chat.channels) {
......
......@@ -625,10 +625,10 @@ function LayoutView(title,frame,parent) {
var msg = chan.messages.shift();
var str = "";
if(msg.nick)
var str = getColor(this.chat.settings.NICK_COLOR) + msg.nick.name + "\1n: " +
getColor(this.chat.settings.TEXT_COLOR) + msg.str;
var str = getColor(this.chat.colors.NICK_COLOR) + msg.nick.name + "\1n: " +
getColor(this.chat.colors.TEXT_COLOR) + msg.str;
else
var str = getColor(this.chat.settings.NOTICE_COLOR) + msg.str;
var str = getColor(this.chat.colors.NOTICE_COLOR) + msg.str;
this.frame.putmsg(str + "\r\n");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment