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.equals(roomJid)) {
// check x element
if(stanza.getVerifier().onlySubelementEquals("x", NamespaceURIs.JABBER_X_DATA)) {
// voice requests
logger.debug("Received voice request for room {}", roomJid);
handleVoiceRequest(from, sendingOccupant, room, stanza, serverRuntimeContext);
} else if(stanza.getVerifier().onlySubelementEquals("x", NamespaceURIs.XEP0045_MUC)) {
// invites/declines
return handleInvites(stanza, from, sendingOccupant, room, serverRuntimeContext);
}
} else 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.getNick());
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?