Commit 6bbfd58f authored by Dave Cridland's avatar Dave Cridland

Merge pull request #551 from sco0ter/actornick

Include nickname in actor element when kick a MUC occupant.
parents 2d7c2213 c3bbe300
...@@ -534,11 +534,12 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -534,11 +534,12 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @param fullJID The full JID of the kicked user (cannot be <tt>null</tt>). * @param fullJID The full JID of the kicked user (cannot be <tt>null</tt>).
* @param actorJID The JID of the actor that initiated the kick (cannot be <tt>null</tt>). * @param actorJID The JID of the actor that initiated the kick (cannot be <tt>null</tt>).
* @param actorNickname The actor nickname.
* @param reason An optional reason why the user was kicked (can be <tt>null</tt>). * @param reason An optional reason why the user was kicked (can be <tt>null</tt>).
* @return the updated presence of the kicked user or null if the user was not in the room. * @return the updated presence of the kicked user or null if the user was not in the room.
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator. * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
*/ */
public Presence kickOccupant(JID fullJID, JID actorJID, String reason) public Presence kickOccupant(JID fullJID, JID actorJID, String actorNickname, String reason)
throws NotAllowedException; throws NotAllowedException;
public IQOwnerHandler getIQOwnerHandler(); public IQOwnerHandler getIQOwnerHandler();
......
...@@ -347,7 +347,7 @@ public class IQAdminHandler { ...@@ -347,7 +347,7 @@ public class IQAdminHandler {
if (MUCRole.Role.moderator != senderRole.getRole()) { if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
presences.add(room.kickOccupant(jid, senderRole.getUserAddress(), presences.add(room.kickOccupant(jid, senderRole.getUserAddress(), senderRole.getNickname(),
item.elementTextTrim("reason"))); item.elementTextTrim("reason")));
} }
} else { } else {
......
...@@ -1848,7 +1848,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -1848,7 +1848,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
x.element("item").addElement("reason").setText(reason); x.element("item").addElement("reason").setText(reason);
} }
x.addElement("status").addAttribute("code", isOutcast ? "301" : "321"); x.addElement("status").addAttribute("code", isOutcast ? "301" : "321");
kickPresence(presence, senderRole.getUserAddress()); kickPresence(presence, senderRole.getUserAddress(), senderRole.getNickname());
} }
} }
updatedPresences.addAll(thisOccupant); updatedPresences.addAll(thisOccupant);
...@@ -2256,7 +2256,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -2256,7 +2256,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
} }
@Override @Override
public Presence kickOccupant(JID jid, JID actorJID, String reason) public Presence kickOccupant(JID jid, JID actorJID, String actorNickname, String reason)
throws NotAllowedException { throws NotAllowedException {
// Update the presence with the new role and inform all occupants // Update the presence with the new role and inform all occupants
Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none); Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
...@@ -2272,7 +2272,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -2272,7 +2272,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
} }
// Effectively kick the occupant from the room // Effectively kick the occupant from the room
kickPresence(updatedPresence, actorJID); kickPresence(updatedPresence, actorJID, actorNickname);
//Inform the other occupants that user has been kicked //Inform the other occupants that user has been kicked
broadcastPresence(updatedPresence, false); broadcastPresence(updatedPresence, false);
...@@ -2287,18 +2287,22 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -2287,18 +2287,22 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
* *
* @param kickPresence the presence of the occupant to kick from the room. * @param kickPresence the presence of the occupant to kick from the room.
* @param actorJID The JID of the actor that initiated the kick or <tt>null</tt> if the info * @param actorJID The JID of the actor that initiated the kick or <tt>null</tt> if the info
* @param nick The actor nickname.
* was not provided. * was not provided.
*/ */
private void kickPresence(Presence kickPresence, JID actorJID) { private void kickPresence(Presence kickPresence, JID actorJID, String nick) {
// Get the role(s) to kick // Get the role(s) to kick
List<MUCRole> occupants = new ArrayList<>(occupantsByNickname.get(kickPresence.getFrom().getResource().toLowerCase())); List<MUCRole> occupants = new ArrayList<>(occupantsByNickname.get(kickPresence.getFrom().getResource().toLowerCase()));
for (MUCRole kickedRole : occupants) { for (MUCRole kickedRole : occupants) {
kickPresence = kickPresence.createCopy();
// 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.toString().length() > 0) { if (actorJID != null && actorJID.toString().length() > 0) {
Element frag = kickPresence.getChildElement( Element frag = kickPresence.getChildElement(
"x", "http://jabber.org/protocol/muc#user"); "x", "http://jabber.org/protocol/muc#user");
frag.element("item").addElement("actor").addAttribute("jid", actorJID.toBareJID()); Element actor = frag.element("item").addElement("actor");
actor.addAttribute("jid", actorJID.toBareJID());
if (nick != null) {
actor.addAttribute("nick", nick);
}
} }
// Send the unavailable presence to the banned user // Send the unavailable presence to the banned user
kickedRole.send(kickPresence); kickedRole.send(kickPresence);
...@@ -2377,7 +2381,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener { ...@@ -2377,7 +2381,7 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
for (MUCRole occupant : occupantsByFullJID.values()) { for (MUCRole occupant : occupantsByFullJID.values()) {
if (occupant.getAffiliation().compareTo(MUCRole.Affiliation.member) > 0) { if (occupant.getAffiliation().compareTo(MUCRole.Affiliation.member) > 0) {
try { try {
presences.add(kickOccupant(occupant.getRoleAddress(), null, presences.add(kickOccupant(occupant.getRoleAddress(), null, null,
LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly"))); LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly")));
} }
catch (NotAllowedException e) { catch (NotAllowedException e) {
......
...@@ -528,7 +528,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -528,7 +528,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
room = role.getChatRoom(); room = role.getChatRoom();
try { try {
kickedPresence = kickedPresence =
room.kickOccupant(user.getAddress(), null, null); room.kickOccupant(user.getAddress(), null, null, null);
// Send the updated presence to the room occupants // Send the updated presence to the room occupants
room.send(kickedPresence); room.send(kickedPresence);
} }
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
MUCRole role = room.getOccupant(nickName); MUCRole role = room.getOccupant(nickName);
if (role != null) { if (role != null) {
try { try {
room.kickOccupant(role.getUserAddress(), XMPPServer.getInstance().createJID(webManager.getUser().getUsername(), null), ""); room.kickOccupant(role.getUserAddress(), XMPPServer.getInstance().createJID(webManager.getUser().getUsername(), null), null, "");
// Log the event // Log the event
webManager.logEvent("kicked MUC occupant "+nickName+" from "+roomName, null); webManager.logEvent("kicked MUC occupant "+nickName+" from "+roomName, null);
// Done, so redirect // Done, so redirect
......
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