Chat user list.

This commit is contained in:
marcins78@gmail.com
2011-09-17 12:14:27 +00:00
parent a6fe101767
commit eb54e6469e
4 changed files with 39 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ public class ChatRoom {
} }
public Set<String> getUsersInRoom() { public Set<String> getUsersInRoom() {
return new HashSet<String>(_chatRoomListeners.keySet()); return new TreeSet<String>(_chatRoomListeners.keySet());
} }
private void shrinkLastMessages() { private void shrinkLastMessages() {

View File

@@ -337,13 +337,14 @@ public class ServerResource {
sendError(Response.Status.NOT_FOUND); sendError(Response.Status.NOT_FOUND);
List<ChatMessage> chatMessages = chatRoom.joinUser(participantId); List<ChatMessage> chatMessages = chatRoom.joinUser(participantId);
Set<String> usersInRoom = chatRoom.getUsersInRoom();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.newDocument(); Document doc = documentBuilder.newDocument();
serializeChatRoomData(room, chatMessages, doc); serializeChatRoomData(room, chatMessages, usersInRoom, doc);
return doc; return doc;
} }
@@ -363,6 +364,7 @@ public class ServerResource {
chatRoom.sendMessage(participantId, StringEscapeUtils.escapeHtml(message)); chatRoom.sendMessage(participantId, StringEscapeUtils.escapeHtml(message));
List<ChatMessage> chatMessages = chatRoom.getPendingMessages(participantId); List<ChatMessage> chatMessages = chatRoom.getPendingMessages(participantId);
Set<String> usersInRoom = chatRoom.getUsersInRoom();
if (chatMessages == null) if (chatMessages == null)
sendError(Response.Status.NOT_FOUND); sendError(Response.Status.NOT_FOUND);
@@ -372,7 +374,7 @@ public class ServerResource {
Document doc = documentBuilder.newDocument(); Document doc = documentBuilder.newDocument();
serializeChatRoomData(room, chatMessages, doc); serializeChatRoomData(room, chatMessages, usersInRoom, doc);
return doc; return doc;
} }
@@ -480,7 +482,7 @@ public class ServerResource {
return sb.toString(); return sb.toString();
} }
private void serializeChatRoomData(String room, List<ChatMessage> chatMessages, Document doc) { private void serializeChatRoomData(String room, List<ChatMessage> chatMessages, Set<String> usersInRoom, Document doc) {
Element chatElem = doc.createElement("chat"); Element chatElem = doc.createElement("chat");
chatElem.setAttribute("roomName", room); chatElem.setAttribute("roomName", room);
doc.appendChild(chatElem); doc.appendChild(chatElem);
@@ -492,6 +494,12 @@ public class ServerResource {
message.appendChild(doc.createTextNode(chatMessage.getMessage())); message.appendChild(doc.createTextNode(chatMessage.getMessage()));
chatElem.appendChild(message); chatElem.appendChild(message);
} }
for (String userInRoom : usersInRoom) {
Element user = doc.createElement("user");
user.appendChild(doc.createTextNode(userInRoom));
chatElem.appendChild(user);
}
} }
private class SerializationVisitor implements ParticipantCommunicationVisitor { private class SerializationVisitor implements ParticipantCommunicationVisitor {

View File

@@ -29,6 +29,9 @@
color: #ff0000; color: #ff0000;
} }
.chatUser {
color: #ffffff;
}
</style> </style>
<link rel="stylesheet" type="text/css" href="css/dark-hive/jquery-ui-1.8.16.custom.css"> <link rel="stylesheet" type="text/css" href="css/dark-hive/jquery-ui-1.8.16.custom.css">
<link rel="stylesheet" type="text/css" href="js/jquery/styles/jquery.spinnercontrol.css"> <link rel="stylesheet" type="text/css" href="js/jquery/styles/jquery.spinnercontrol.css">
@@ -75,7 +78,7 @@
$("#user").append("You may <a href='deckBuild.html?participantId=" + participantId + "'>edit your deck</a>.<br/>"); $("#user").append("You may <a href='deckBuild.html?participantId=" + participantId + "'>edit your deck</a>.<br/>");
$("#user").append("Create a table or join one where other player is waiting to start a game."); $("#user").append("Create a table or join one where other player is waiting to start a game.");
var chat = new ChatBoxUI("default", $("#chat"), "/gemp-lotr/server"); var chat = new ChatBoxUI("default", $("#chat"), "/gemp-lotr/server", true);
chat.setBounds(2, 2, 780 - 4, 200 - 4); chat.setBounds(2, 2, 780 - 4, 200 - 4);
var hall = new GempLotrHallUI($("#hall"), "/gemp-lotr/server", chat); var hall = new GempLotrHallUI($("#hall"), "/gemp-lotr/server", chat);

View File

@@ -4,9 +4,10 @@ var ChatBoxUI = Class.extend({
communication: null, communication: null,
chatMessagesDiv: null, chatMessagesDiv: null,
chatTalkDiv: null, chatTalkDiv: null,
chatListDiv: null,
talkBoxHeight: 25, talkBoxHeight: 25,
init: function(name, div, url) { init: function(name, div, url, showList) {
var that = this; var that = this;
this.name = name; this.name = name;
this.div = div; this.div = div;
@@ -17,6 +18,10 @@ var ChatBoxUI = Class.extend({
this.chatMessagesDiv = $("<div class='chatMessages'></div>"); this.chatMessagesDiv = $("<div class='chatMessages'></div>");
this.chatTalkDiv = $("<input class='chatTalk'>"); this.chatTalkDiv = $("<input class='chatTalk'>");
if (showList) {
this.chatListDiv = $("<div class='userList'></div>");
this.div.append(this.chatListDiv);
}
this.div.append(this.chatMessagesDiv); this.div.append(this.chatMessagesDiv);
this.div.append(this.chatTalkDiv); this.div.append(this.chatTalkDiv);
@@ -45,7 +50,13 @@ var ChatBoxUI = Class.extend({
setBounds: function(x, y, width, height) { setBounds: function(x, y, width, height) {
var talkBoxPadding = 3; var talkBoxPadding = 3;
this.chatMessagesDiv.css({ position: "absolute", left: x + "px", top: y + "px", width: width, height: height - this.talkBoxHeight - 3 * talkBoxPadding, overflow: "auto" }); var userListWidth = 150;
if (this.chatListDiv == null)
userListWidth = 0;
if (this.chatListDiv != null)
this.chatListDiv.css({ position: "absolute", left: x + width - userListWidth + "px", top: y + "px", width: userListWidth, height: height - this.talkBoxHeight - 3 * talkBoxPadding, overflow: "auto" });
this.chatMessagesDiv.css({ position: "absolute", left: x + "px", top: y + "px", width: width - userListWidth, height: height - this.talkBoxHeight - 3 * talkBoxPadding, overflow: "auto" });
this.chatTalkDiv.css({ position: "absolute", left: x + talkBoxPadding + "px", top: y - 2 * talkBoxPadding + (height - this.talkBoxHeight) + "px", width: width - 3 * talkBoxPadding , height: this.talkBoxHeight }); this.chatTalkDiv.css({ position: "absolute", left: x + talkBoxPadding + "px", top: y - 2 * talkBoxPadding + (height - this.talkBoxHeight) + "px", width: width - 3 * talkBoxPadding , height: this.talkBoxHeight });
}, },
@@ -70,6 +81,16 @@ var ChatBoxUI = Class.extend({
this.appendMessage("<b>" + from + ":</b> " + text); this.appendMessage("<b>" + from + ":</b> " + text);
} }
if (this.chatListDiv != null) {
this.chatListDiv.html("");
var users = root.getElementsByTagName("user");
for (var i = 0; i < users.length; i++) {
var user = users[i];
var userName = user.childNodes[0].nodeValue;
this.chatListDiv.append("<div class='chatUser'>" + userName + "</div>");
}
}
var that = this; var that = this;
if (processAgain) if (processAgain)