|
// Messages class
/**
* Chat messages processing and formatting class.
*/
function Messages() {
this.addMessage = Messages_addMessage;
this.formatMessage = Messages_formatMessage;
this.getMessages = Messages_getMessages;
this.formatAll = Messages_formatAll;
this.replaceNewLine = Messages_replaceNewLine;
this.formatSysMessage = Messages_formatSysMessage;
this.addSysMessage = Messages_addSysMessage;
this.identifier = "Messages";
}
/**
* Formats all messages in reversing order as HTML.
* @return HTML with messages.
*/
function Messages_formatAll(roomID) {
var strMessages = "";
var objMessages = this.getMessages(roomID);
var items = objMessages.getItems();
var i = items.length-1;
for(;i >= 0; i--) {
var x = items.item(i);
strMessages += x.text;
strMessages += "<BR>\n"
}
return strMessages;
}
/**
* Adds new message and performs message formatting.
* @param clientIP IP address of message sender.
* @param strNick nick name of sender.
* @param strMessage textual message contents.
* @param moodType mood type for current message.
*/
function Messages_addMessage(roomID, clientIP, strNick, strMessage, moodType) {
var filter = new IncorrectInputFilter;
strMessage = filter.processText(strMessage);
strNick = Server.HTMLEncode(strNick);
strMessage = Server.HTMLEncode(strMessage);
strMessage = this.replaceNewLine(strMessage);
var strFormatted = this.formatMessage(clientIP, strNick, strMessage, moodType);
var messages = this.getMessages(roomID);
messages.add(strFormatted);
}
/**
* Addition of a new system message for the chat.
*/
function Messages_addSysMessage(roomID, strMessage) {
strMessage = Server.HTMLEncode(strMessage);
var filter = new IncorrectInputFilter;
strMessage = filter.processText(strMessage);
var strFormatted = this.formatSysMessage(strMessage);
var messages = this.getMessages(roomID)
messages.add(strFormatted);
}
/**
* Performs single system message formatting.
* @param strMessage textual message contents.
* @return Formatted message HTML.
*/
function Messages_formatSysMessage(strMessage) {
var strFormatted = "<font color=\"red\">System: " + strMessage + "</font>";
return strFormatted;
}
/**
* Performs single message formatting.
* @param clientIP IP address of message sender.
* @param strNick nick name of sender.
* @param strMessage textual message contents.
* @param moodType mood type for current message.
* @return Formatted message HTML.
*/
function Messages_formatMessage(clientIP, strNick, strMessage, moodType) {
var strFormatted = "<font color=\"#006666\">" + strNick
+ " (" + clientIP + "): " + strMessage + "</font>";
if(moodType > 0 && moodType <= 5) {
strFormatted += " <img src=\"img/mood" + moodType + ".gif\">";
}
return strFormatted;
}
/**
* Replaces all new line symbols to be visible in HTML.
*/
function Messages_replaceNewLine(source) {
var re = /\n/g;
return source.replace(re, "<BR>");
}
/**
* Prepares messages store of specified room for easy accessing.
* @return LimitedXML object with shared messages.
*/
function Messages_getMessages(roomID) {
var allRooms = new SharedXML(this.identifier);
var roomNode = allRooms.findNode(roomID);
if(roomNode == null) {
// Create room if not exists.
roomNode = allRooms.insertNode(roomID);
}
if(roomNode != null) {
return new LimitedXML(roomNode, getMaxMessages());
}
}
// Messages class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here