}
logger.debug("Received groupchat message to {}", roomJid);
Room room = conference.findRoom(roomJid);
if(room != null) {
Occupant sendingOccupant = room.findOccupantByJID(from);
// sender must be participant in room
if(sendingOccupant != null) {
Entity roomAndSendingNick = new EntityImpl(room.getJID(), sendingOccupant.getName());
if(sendingOccupant.hasVoice()) {
// relay message to all occupants in room
try {
if(stanza.getSubjects() != null && !stanza.getSubjects().isEmpty()) {
// subject message
if(!room.isRoomType(RoomType.OpenSubject) && !sendingOccupant.isModerator()) {
// room only allows moderators to change the subject, and sender is not a moderator
return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.AUTH, StanzaErrorCondition.FORBIDDEN, stanza);
}
}
} catch (XMLSemanticError e) {
// not a subject message, ignore exception
}
logger.debug("Relaying message to all room occupants");
for(Occupant occupent : room.getOccupants()) {
logger.debug("Relaying message to {}", occupent);
List<Attribute> replaceAttributes = new ArrayList<Attribute>();
replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
replaceAttributes.add(new Attribute("to", occupent.getJid().getFullQualifiedName()));
relayStanza(occupent.getJid(),
StanzaBuilder.createClone(stanza, true, replaceAttributes).build(),
serverRuntimeContext);
}
// add to discussion history
room.getHistory().append(stanza, sendingOccupant);
} else {
return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.FORBIDDEN, stanza);
}
} else {
return createMessageErrorStanza(room.getJID(), from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.NOT_ACCEPTABLE, stanza);
}
} else {
return createMessageErrorStanza(moduleDomain, from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.ITEM_NOT_FOUND, stanza);
}
} else if(type == null || type == MessageStanzaType.CHAT || type == MessageStanzaType.NORMAL) {
// private message
logger.debug("Received direct message to {}", roomWithNickJid);
Room room = conference.findRoom(roomJid);
if(room != null) {
Occupant sendingOccupant = room.findOccupantByJID(from);
// sender must be participant in room
if(roomWithNickJid.isResourceSet()) {
if(sendingOccupant != null) {
// got resource, private message for occupant
Occupant receivingOccupant = room.findOccupantByNick(roomWithNickJid.getResource());
// must be sent to an existing occupant in the room
if(receivingOccupant != null) {
Entity roomAndSendingNick = new EntityImpl(room.getJID(), sendingOccupant.getName());
logger.debug("Relaying message to {}", receivingOccupant);
List<Attribute> replaceAttributes = new ArrayList<Attribute>();
replaceAttributes.add(new Attribute("from", roomAndSendingNick.getFullQualifiedName()));
replaceAttributes.add(new Attribute("to", receivingOccupant.getJid().getFullQualifiedName()));
relayStanza(receivingOccupant.getJid(),
StanzaBuilder.createClone(stanza, true, replaceAttributes).build(),
serverRuntimeContext);
} else {
// TODO correct error?
return createMessageErrorStanza(moduleDomain, from, stanza.getID(), StanzaErrorType.MODIFY, StanzaErrorCondition.ITEM_NOT_FOUND, stanza);