Commit 9c882c20 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1) Fixed ClassCastException. JM-53

2) Removed UnauthorizedException as a thrown exception in methods that was being used for ACL.
3) Adds last known room's subject to the room's history after the room was loaded from the DB.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@487 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8f8592ef
...@@ -319,6 +319,9 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -319,6 +319,9 @@ public class MUCRoomImpl implements MUCRoom {
} }
public MUCRole getOccupant(String nickname) throws UserNotFoundException { public MUCRole getOccupant(String nickname) throws UserNotFoundException {
if (nickname == null) {
throw new UserNotFoundException();
}
MUCRole role = occupants.get(nickname.toLowerCase()); MUCRole role = occupants.get(nickname.toLowerCase());
if (role != null) { if (role != null) {
return role; return role;
...@@ -329,7 +332,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -329,7 +332,7 @@ public class MUCRoomImpl implements MUCRoom {
public List<MUCRole> getOccupantsByBareJID(String jid) throws UserNotFoundException { public List<MUCRole> getOccupantsByBareJID(String jid) throws UserNotFoundException {
List<MUCRole> roles = occupantsByBareJID.get(jid); List<MUCRole> roles = occupantsByBareJID.get(jid);
if (roles != null && !roles.isEmpty()) { if (roles != null && !roles.isEmpty()) {
return (List<MUCRole>)Collections.unmodifiableCollection(roles); return Collections.unmodifiableList(roles);
} }
throw new UserNotFoundException(); throw new UserNotFoundException();
} }
...@@ -342,7 +345,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -342,7 +345,7 @@ public class MUCRoomImpl implements MUCRoom {
throw new UserNotFoundException(); throw new UserNotFoundException();
} }
public Iterator<MUCRole> getOccupants() throws UnauthorizedException { public Iterator<MUCRole> getOccupants() {
return occupants.values().iterator(); return occupants.values().iterator();
} }
...@@ -350,7 +353,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -350,7 +353,7 @@ public class MUCRoomImpl implements MUCRoom {
return occupants.size(); return occupants.size();
} }
public boolean hasOccupant(String nickname) throws UnauthorizedException { public boolean hasOccupant(String nickname) {
return occupants.containsKey(nickname.toLowerCase()); return occupants.containsKey(nickname.toLowerCase());
} }
...@@ -549,7 +552,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -549,7 +552,7 @@ public class MUCRoomImpl implements MUCRoom {
return joinRole; return joinRole;
} }
public void leaveRoom(String nickname) throws UnauthorizedException, UserNotFoundException { public void leaveRoom(String nickname) throws UserNotFoundException {
MUCRole leaveRole = null; MUCRole leaveRole = null;
lock.writeLock().lock(); lock.writeLock().lock();
try { try {
...@@ -617,7 +620,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -617,7 +620,7 @@ public class MUCRoomImpl implements MUCRoom {
occupantsByFullJID.remove(user.getAddress().toStringPrep()); occupantsByFullJID.remove(user.getAddress().toStringPrep());
} }
public void destroyRoom(String alternateJID, String reason) throws UnauthorizedException { public void destroyRoom(String alternateJID, String reason) {
MUCRole leaveRole = null; MUCRole leaveRole = null;
lock.writeLock().lock(); lock.writeLock().lock();
try { try {
...@@ -684,7 +687,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -684,7 +687,7 @@ public class MUCRoomImpl implements MUCRoom {
return presence; return presence;
} }
public void serverBroadcast(String msg) throws UnauthorizedException { public void serverBroadcast(String msg) {
Message message = new MessageImpl(); Message message = new MessageImpl();
message.setType(Message.GROUP_CHAT); message.setType(Message.GROUP_CHAT);
message.setBody(msg); message.setBody(msg);
...@@ -717,17 +720,17 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -717,17 +720,17 @@ public class MUCRoomImpl implements MUCRoom {
} }
} }
public void send(Message packet) throws UnauthorizedException { public void send(Message packet) {
// normal groupchat // normal groupchat
roomHistory.addMessage(packet); roomHistory.addMessage(packet);
broadcast(packet); broadcast(packet);
} }
public void send(Presence packet) throws UnauthorizedException { public void send(Presence packet) {
broadcastPresence(packet); broadcastPresence(packet);
} }
public void send(IQ packet) throws UnauthorizedException { public void send(IQ packet) {
packet = (IQ) packet.createDeepCopy(); packet = (IQ) packet.createDeepCopy();
packet.setError(XMPPError.Code.BAD_REQUEST); packet.setError(XMPPError.Code.BAD_REQUEST);
packet.setRecipient(packet.getSender()); packet.setRecipient(packet.getSender());
...@@ -885,15 +888,15 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -885,15 +888,15 @@ public class MUCRoomImpl implements MUCRoom {
return crJID; return crJID;
} }
public void send(Message packet) throws UnauthorizedException { public void send(Message packet) {
room.send(packet); room.send(packet);
} }
public void send(Presence packet) throws UnauthorizedException { public void send(Presence packet) {
room.send(packet); room.send(packet);
} }
public void send(IQ packet) throws UnauthorizedException { public void send(IQ packet) {
room.send(packet); room.send(packet);
} }
...@@ -1133,7 +1136,11 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1133,7 +1136,11 @@ public class MUCRoomImpl implements MUCRoom {
throw new ConflictException(); throw new ConflictException();
} }
// Update the presence with the new affiliation and inform all occupants // Update the presence with the new affiliation and inform all occupants
String actorJID = senderRole.getChatUser().getAddress().toBareStringPrep(); String actorJID = null;
// actorJID will be null if the room itself (ie. via admin console) made the request
if (senderRole.getChatUser() != null) {
actorJID = senderRole.getChatUser().getAddress().toBareStringPrep();
}
List<Presence> updatedPresences = changeOccupantAffiliation( List<Presence> updatedPresences = changeOccupantAffiliation(
bareJID, bareJID,
MUCRole.OUTCAST, MUCRole.OUTCAST,
...@@ -1199,7 +1206,8 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1199,7 +1206,8 @@ public class MUCRoomImpl implements MUCRoom {
throw new ConflictException(); throw new ConflictException();
} }
List<Presence> updatedPresences = null; List<Presence> updatedPresences = null;
boolean wasMember = members.containsKey(bareJID); boolean wasMember = members.containsKey(bareJID) || admins.contains(bareJID) ||
owners.contains(bareJID);
// Remove the user from ALL the affiliation lists // Remove the user from ALL the affiliation lists
if (removeOwner(bareJID)) { if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.OWNER; oldAffiliation = MUCRole.OWNER;
...@@ -1283,8 +1291,12 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1283,8 +1291,12 @@ public class MUCRoomImpl implements MUCRoom {
public void changeSubject(Message packet, MUCRole role) throws UnauthorizedException, public void changeSubject(Message packet, MUCRole role) throws UnauthorizedException,
ForbiddenException { ForbiddenException {
if ((canOccupantsChangeSubject() && role.getRole() > MUCRole.VISITOR) || if ((canOccupantsChangeSubject() && role.getRole() < MUCRole.VISITOR) ||
MUCRole.MODERATOR == role.getRole()) { MUCRole.MODERATOR == role.getRole()) {
// Do nothing if the new subject is the same as the existing one
if (packet.getSubject().equals(subject)) {
return;
}
// Set the new subject to the room // Set the new subject to the room
subject = packet.getSubject(); subject = packet.getSubject();
MUCPersistenceManager.updateRoomSubject(this, subject); MUCPersistenceManager.updateRoomSubject(this, subject);
...@@ -1303,6 +1315,15 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1303,6 +1315,15 @@ public class MUCRoomImpl implements MUCRoom {
public void setSubject(String subject) { public void setSubject(String subject) {
this.subject = subject; this.subject = subject;
// TODO Remove this when persistent room's history gets implemented
// Add the room's subject to the history
if (subject != null && subject.length() > 0) {
Message message = new MessageImpl();
message.setType(Message.GROUP_CHAT);
message.setSubject(subject);
message.setSender(getRole().getRoleAddress());
roomHistory.addMessage(message);
}
} }
public void sendInvitation(String to, String reason, MUCRole senderRole, Session session) public void sendInvitation(String to, String reason, MUCRole senderRole, Session session)
...@@ -1317,8 +1338,11 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1317,8 +1338,11 @@ public class MUCRoomImpl implements MUCRoom {
message.setSender(role.getRoleAddress()); message.setSender(role.getRoleAddress());
message.setRecipient(XMPPAddress.parseJID(to)); message.setRecipient(XMPPAddress.parseJID(to));
MetaDataFragment frag = new MetaDataFragment("http://jabber.org/protocol/muc#user", "x"); MetaDataFragment frag = new MetaDataFragment("http://jabber.org/protocol/muc#user", "x");
frag.setProperty("x.invite:from", senderRole.getChatUser().getAddress() // ChatUser will be null if the room itself (ie. via admin console) made the request
.toBareStringPrep()); if (senderRole.getChatUser() != null) {
frag.setProperty("x.invite:from", senderRole.getChatUser().getAddress()
.toBareStringPrep());
}
if (reason != null && reason.length() > 0) { if (reason != null && reason.length() > 0) {
frag.setProperty("x.invite.reason", reason); frag.setProperty("x.invite.reason", reason);
} }
...@@ -1366,11 +1390,11 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1366,11 +1390,11 @@ public class MUCRoomImpl implements MUCRoom {
} }
public Iterator<String> getOwners() { public Iterator<String> getOwners() {
return Collections.unmodifiableCollection(owners).iterator(); return Collections.unmodifiableList(owners).iterator();
} }
public Iterator<String> getAdmins() { public Iterator<String> getAdmins() {
return Collections.unmodifiableCollection(admins).iterator(); return Collections.unmodifiableList(admins).iterator();
} }
public Iterator<String> getMembers() { public Iterator<String> getMembers() {
...@@ -1378,7 +1402,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1378,7 +1402,7 @@ public class MUCRoomImpl implements MUCRoom {
} }
public Iterator<String> getOutcasts() { public Iterator<String> getOutcasts() {
return Collections.unmodifiableCollection(outcasts).iterator(); return Collections.unmodifiableList(outcasts).iterator();
} }
public Iterator<MUCRole> getModerators() { public Iterator<MUCRole> getModerators() {
...@@ -1480,21 +1504,16 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1480,21 +1504,16 @@ public class MUCRoomImpl implements MUCRoom {
// Get the role to kick // Get the role to kick
kickedRole = occupants.get(kickPresence.getSender().getResourcePrep()); kickedRole = occupants.get(kickPresence.getSender().getResourcePrep());
if (kickedRole != null) { if (kickedRole != null) {
try { kickPresence = (Presence) kickPresence.createDeepCopy();
kickPresence = (Presence) kickPresence.createDeepCopy(); // Add the actor's JID that kicked this user from the room
// Add the actor's JID that kicked this user from the room if (actorJID != null && actorJID.trim().length() > 0) {
if (actorJID != null && actorJID.trim().length() > 0) { MetaDataFragment frag = (MetaDataFragment) kickPresence.getFragment(
MetaDataFragment frag = (MetaDataFragment) kickPresence.getFragment( "x",
"x", "http://jabber.org/protocol/muc#user");
"http://jabber.org/protocol/muc#user"); frag.setProperty("x.item.actor:jid", actorJID);
frag.setProperty("x.item.actor:jid", actorJID);
}
// Send the unavailable presence to the banned user
kickedRole.send(kickPresence);
}
catch (UnauthorizedException e) {
// Do nothing
} }
// Send the unavailable presence to the banned user
kickedRole.send(kickPresence);
// Remove the occupant from the room's occupants lists // Remove the occupant from the room's occupants lists
removeOccupantRole(kickedRole); removeOccupantRole(kickedRole);
try { try {
......
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