*/
@SuppressWarnings("unchecked")
public int sendMessageWithClient(Object newMessage) {
try {
IConnection current = Red5.getConnectionLocal();
Client currentClient = this.sessionManager.getClientByStreamId(current.getClient().getId(), null);
Long room_id = currentClient.getRoom_id();
log.debug("room_id: " + room_id);
if (room_id == null) {
return 1; //TODO weird
}
Long user_level = userManager.getUserLevelByID(currentClient.getUser_id());
Room room = roomManager.getRoomById(user_level, room_id);
@SuppressWarnings("rawtypes")
ArrayList messageMap = (ArrayList) newMessage;
// adding delimiter space, cause otherwise an emoticon in the last
// string would not be found
String messageText = messageMap.get(4) + " ";
LinkedList<String[]> parsedStringObjects = ChatString.parseChatString(messageText, emoticonsManager.getEmotfilesList(), room.getAllowFontStyles());
// log.error("parsedStringObjects"+parsedStringObjects.size());
log.debug("size:" + messageMap.size());
messageMap.add(parsedStringObjects);
newMessage = messageMap;
boolean needModeration = Boolean.valueOf("" + messageMap.get(9));
List<HashMap<String, Object>> myChatList = myChats.get(room_id);
if (myChatList == null) myChatList = new LinkedList<HashMap<String, Object>>();
HashMap<String, Object> hsm = new HashMap<String, Object>();
hsm.put("message", newMessage);
String publicSID = "" + messageMap.get(6);
if (!publicSID.equals(currentClient.getPublicSID())) {
hsm.put("client", sessionManager.getClientByPublicSID("" + messageMap.get(6), false, null));
//need to remove unconfirmed chat message if any
for (int i = myChatList.size() - 1; i > -1; --i) {
Client msgClient = (Client)myChatList.get(i).get("client");
@SuppressWarnings("rawtypes")
List msgList = (List)myChatList.get(i).get("message");
if (publicSID.equals(msgClient.getPublicSID())
&& ("" + msgList.get(4)).equals(messageMap.get(4))
&& ("" + msgList.get(1)).equals(messageMap.get(1))
&& Boolean.valueOf("" + msgList.get(9))) {
myChatList.remove(i);
break;
}
}
} else {
// add server time
messageMap.set(1, parseDateAsTimeString());
hsm.put("client", currentClient);
}
if (myChatList.size() == chatRoomHistory) myChatList.remove(0);
myChatList.add(hsm);
myChats.put(room_id, myChatList);
log.debug("SET CHATROOM: " + room_id);
//broadcast to everybody in the room/domain
Collection<Set<IConnection>> conCollection = current.getScope().getConnections();
for (Set<IConnection> conset : conCollection) {
for (IConnection conn : conset) {
if (conn != null) {
if (conn instanceof IServiceCapableConnection) {
Client rcl = this.sessionManager.getClientByStreamId(conn.getClient().getId(), null);
if (rcl == null) {
continue;
}
if (rcl.getIsAVClient()) {
continue;
}
if (rcl.getIsScreenClient() != null && rcl.getIsScreenClient()) {
continue;
}
if (needModeration && Boolean.TRUE != rcl.getIsMod() && Boolean.TRUE != rcl.getIsSuperModerator()) {
continue;
}
((IServiceCapableConnection) conn).invoke("sendVarsToMessageWithClient",new Object[] { hsm }, this);
}
}