Commit 2a190439 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

IQ packets can be delivered between room occupants. JM-436

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@2979 b35dd754-fafc-0310-a699-88a17e54d16e
parent 68b98892
...@@ -466,13 +466,15 @@ public interface MUCRoom { ...@@ -466,13 +466,15 @@ public interface MUCRoom {
public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException; public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException;
/** /**
* Sends a private message to a selected occupant. * Sends a private packet to a selected occupant. The packet can be a Message for private
* conversation between room occupants or IQ packets when an occupant wants to send IQ packets
* to other room occupants.
* *
* @param message The message to send. * @param packet The packet to send.
* @param senderRole the role of the user that is trying to send a public message. * @param senderRole the role of the user that is trying to send a public message.
* @throws NotFoundException If the user is sending a message to a room JID that does not exist. * @throws NotFoundException If the user is sending a packet to a room JID that does not exist.
*/ */
public void sendPrivateMessage(Message message, MUCRole senderRole) throws NotFoundException; public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException;
/** /**
* Kicks a user from the room. If the user was in the room, the returned updated presence will * Kicks a user from the room. If the user was in the room, the returned updated presence will
......
...@@ -750,12 +750,12 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -750,12 +750,12 @@ public class MUCRoomImpl implements MUCRoom {
send(message); send(message);
} }
public void sendPrivateMessage(Message message, MUCRole senderRole) throws NotFoundException { public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException {
String resource = message.getTo().getResource(); String resource = packet.getTo().getResource();
MUCRole occupant = occupants.get(resource.toLowerCase()); MUCRole occupant = occupants.get(resource.toLowerCase());
if (occupant != null) { if (occupant != null) {
message.setFrom(senderRole.getRoleAddress()); packet.setFrom(senderRole.getRoleAddress());
occupant.send(message); occupant.send(packet);
} }
else { else {
throw new NotFoundException(); throw new NotFoundException();
......
...@@ -216,7 +216,7 @@ public class MUCUserImpl implements MUCUser { ...@@ -216,7 +216,7 @@ public class MUCUserImpl implements MUCUser {
else if (resource != null else if (resource != null
&& (Message.Type.chat == type || Message.Type.normal == type)) { && (Message.Type.chat == type || Message.Type.normal == type)) {
// An occupant is trying to send a private message // An occupant is trying to send a private message
role.getChatRoom().sendPrivateMessage(packet, role); role.getChatRoom().sendPrivatePacket(packet, role);
} }
else if (resource == null && Message.Type.normal == type) { else if (resource == null && Message.Type.normal == type) {
// An occupant could be sending an invitation or declining an // An occupant could be sending an invitation or declining an
...@@ -321,12 +321,21 @@ public class MUCUserImpl implements MUCUser { ...@@ -321,12 +321,21 @@ public class MUCUserImpl implements MUCUser {
role.getChatRoom().getIQAdminHandler().handleIQ(packet, role); role.getChatRoom().getIQAdminHandler().handleIQ(packet, role);
} }
else { else {
sendErrorPacket(packet, PacketError.Condition.bad_request); if (packet.getTo().getResource() != null) {
// User is sending an IQ packet to another room occupant
role.getChatRoom().sendPrivatePacket(packet, role);
}
else {
sendErrorPacket(packet, PacketError.Condition.bad_request);
}
} }
} }
catch (ForbiddenException e) { catch (ForbiddenException e) {
sendErrorPacket(packet, PacketError.Condition.forbidden); sendErrorPacket(packet, PacketError.Condition.forbidden);
} }
catch (NotFoundException e) {
sendErrorPacket(packet, PacketError.Condition.recipient_unavailable);
}
catch (ConflictException e) { catch (ConflictException e) {
sendErrorPacket(packet, PacketError.Condition.conflict); sendErrorPacket(packet, PacketError.Condition.conflict);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment