1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

. Modified #nicknameChanged to include old and new nicknames. SMACK-55

. Modified banning and kicking to include reason and actor. SMACK-81

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3038 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-11-08 17:15:18 +00:00 committed by gato
parent 254c4a450a
commit f12f1c2a1e
4 changed files with 80 additions and 35 deletions

View file

@ -37,7 +37,7 @@ public class DefaultParticipantStatusListener implements ParticipantStatusListen
public void left(String participant) { public void left(String participant) {
} }
public void kicked(String participant) { public void kicked(String participant, String actor, String reason) {
} }
public void voiceGranted(String participant) { public void voiceGranted(String participant) {
@ -46,7 +46,7 @@ public class DefaultParticipantStatusListener implements ParticipantStatusListen
public void voiceRevoked(String participant) { public void voiceRevoked(String participant) {
} }
public void banned(String participant) { public void banned(String participant, String actor, String reason) {
} }
public void membershipGranted(String participant) { public void membershipGranted(String participant) {
@ -73,7 +73,7 @@ public class DefaultParticipantStatusListener implements ParticipantStatusListen
public void adminRevoked(String participant) { public void adminRevoked(String participant) {
} }
public void nicknameChanged(String nickname) { public void nicknameChanged(String participant, String newNickname) {
} }
} }

View file

@ -1986,7 +1986,7 @@ public class MultiUserChat {
} }
} }
private void fireParticipantStatusListeners(String methodName, String param) { private void fireParticipantStatusListeners(String methodName, List params) {
ParticipantStatusListener[] listeners = null; ParticipantStatusListener[] listeners = null;
synchronized (participantStatusListeners) { synchronized (participantStatusListeners) {
listeners = new ParticipantStatusListener[participantStatusListeners.size()]; listeners = new ParticipantStatusListener[participantStatusListeners.size()];
@ -1994,12 +1994,13 @@ public class MultiUserChat {
} }
try { try {
// Get the method to execute based on the requested methodName and parameter // Get the method to execute based on the requested methodName and parameter
Method method = Class[] classes = new Class[params.size()];
ParticipantStatusListener.class.getDeclaredMethod( for (int i=0;i<params.size(); i++) {
methodName, classes[i] = String.class;
new Class[] { String.class }); }
Method method = ParticipantStatusListener.class.getDeclaredMethod(methodName, classes);
for (int i = 0; i < listeners.length; i++) { for (int i = 0; i < listeners.length; i++) {
method.invoke(listeners[i], new Object[] {param}); method.invoke(listeners[i], params.toArray());
} }
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
@ -2085,7 +2086,9 @@ public class MultiUserChat {
else { else {
// A new occupant has joined the room // A new occupant has joined the room
if (!isUserStatusModification) { if (!isUserStatusModification) {
fireParticipantStatusListeners("joined", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("joined", params);
} }
} }
} }
@ -2104,7 +2107,9 @@ public class MultiUserChat {
} else { } else {
// An occupant has left the room // An occupant has left the room
if (!isUserStatusModification) { if (!isUserStatusModification) {
fireParticipantStatusListeners("left", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("left", params);
} }
} }
} }
@ -2180,7 +2185,9 @@ public class MultiUserChat {
fireUserStatusListeners("voiceGranted", new Object[] {}); fireUserStatusListeners("voiceGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("voiceGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("voiceGranted", params);
} }
} }
// The participant's voice was revoked from the room // The participant's voice was revoked from the room
@ -2191,7 +2198,9 @@ public class MultiUserChat {
fireUserStatusListeners("voiceRevoked", new Object[] {}); fireUserStatusListeners("voiceRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("voiceRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("voiceRevoked", params);
} }
} }
// Moderator privileges were granted to a participant // Moderator privileges were granted to a participant
@ -2201,14 +2210,18 @@ public class MultiUserChat {
fireUserStatusListeners("voiceGranted", new Object[] {}); fireUserStatusListeners("voiceGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("voiceGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("voiceGranted", params);
} }
} }
if (isUserModification) { if (isUserModification) {
fireUserStatusListeners("moderatorGranted", new Object[] {}); fireUserStatusListeners("moderatorGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("moderatorGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("moderatorGranted", params);
} }
} }
// Moderator privileges were revoked from a participant // Moderator privileges were revoked from a participant
@ -2218,14 +2231,18 @@ public class MultiUserChat {
fireUserStatusListeners("voiceRevoked", new Object[] {}); fireUserStatusListeners("voiceRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("voiceRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("voiceRevoked", params);
} }
} }
if (isUserModification) { if (isUserModification) {
fireUserStatusListeners("moderatorRevoked", new Object[] {}); fireUserStatusListeners("moderatorRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("moderatorRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("moderatorRevoked", params);
} }
} }
} }
@ -2284,7 +2301,9 @@ public class MultiUserChat {
fireUserStatusListeners("ownershipRevoked", new Object[] {}); fireUserStatusListeners("ownershipRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("ownershipRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("ownershipRevoked", params);
} }
} }
// The user's administrative privileges to the room were revoked // The user's administrative privileges to the room were revoked
@ -2293,7 +2312,9 @@ public class MultiUserChat {
fireUserStatusListeners("adminRevoked", new Object[] {}); fireUserStatusListeners("adminRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("adminRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("adminRevoked", params);
} }
} }
// The user's membership to the room was revoked // The user's membership to the room was revoked
@ -2302,7 +2323,9 @@ public class MultiUserChat {
fireUserStatusListeners("membershipRevoked", new Object[] {}); fireUserStatusListeners("membershipRevoked", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("membershipRevoked", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("membershipRevoked", params);
} }
} }
@ -2312,7 +2335,9 @@ public class MultiUserChat {
fireUserStatusListeners("ownershipGranted", new Object[] {}); fireUserStatusListeners("ownershipGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("ownershipGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("ownershipGranted", params);
} }
} }
// The user was granted administrative privileges to the room // The user was granted administrative privileges to the room
@ -2321,7 +2346,9 @@ public class MultiUserChat {
fireUserStatusListeners("adminGranted", new Object[] {}); fireUserStatusListeners("adminGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("adminGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("adminGranted", params);
} }
} }
// The user was granted membership to the room // The user was granted membership to the room
@ -2330,7 +2357,9 @@ public class MultiUserChat {
fireUserStatusListeners("membershipGranted", new Object[] {}); fireUserStatusListeners("membershipGranted", new Object[] {});
} }
else { else {
fireParticipantStatusListeners("membershipGranted", from); List params = new ArrayList();
params.add(from);
fireParticipantStatusListeners("membershipGranted", params);
} }
} }
} }
@ -2364,7 +2393,11 @@ public class MultiUserChat {
userHasLeft(); userHasLeft();
} }
else { else {
fireParticipantStatusListeners("kicked", from); List params = new ArrayList();
params.add(from);
params.add(mucUser.getItem().getActor());
params.add(mucUser.getItem().getReason());
fireParticipantStatusListeners("kicked", params);
} }
} }
// A user was banned from the room // A user was banned from the room
@ -2383,8 +2416,11 @@ public class MultiUserChat {
userHasLeft(); userHasLeft();
} }
else { else {
// TODO Check if we have to send the JID of the banned user List params = new ArrayList();
fireParticipantStatusListeners("banned", from); params.add(from);
params.add(mucUser.getItem().getActor());
params.add(mucUser.getItem().getReason());
fireParticipantStatusListeners("banned", params);
} }
} }
// A user's membership was revoked from the room // A user's membership was revoked from the room
@ -2403,7 +2439,10 @@ public class MultiUserChat {
} }
// A occupant has changed his nickname in the room // A occupant has changed his nickname in the room
else if ("303".equals(code)) { else if ("303".equals(code)) {
fireParticipantStatusListeners("nicknameChanged", mucUser.getItem().getNick()); List params = new ArrayList();
params.add(from);
params.add(mucUser.getItem().getNick());
fireParticipantStatusListeners("nicknameChanged", params);
} }
} }

View file

@ -53,8 +53,10 @@ public interface ParticipantStatusListener {
* *
* @param participant the participant that was kicked from the room * @param participant the participant that was kicked from the room
* (e.g. room@conference.jabber.org/nick). * (e.g. room@conference.jabber.org/nick).
* @param actor the moderator that kicked the occupant from the room (e.g. user@host.org).
* @param reason the reason provided by the actor to kick the occupant from the room.
*/ */
public abstract void kicked(String participant); public abstract void kicked(String participant, String actor, String reason);
/** /**
* Called when a moderator grants voice to a visitor. This means that the visitor * Called when a moderator grants voice to a visitor. This means that the visitor
@ -81,8 +83,10 @@ public interface ParticipantStatusListener {
* *
* @param participant the participant that was banned from the room * @param participant the participant that was banned from the room
* (e.g. room@conference.jabber.org/nick). * (e.g. room@conference.jabber.org/nick).
* @param actor the administrator that banned the occupant (e.g. user@host.org).
* @param reason the reason provided by the administrator to ban the occupant.
*/ */
public abstract void banned(String participant); public abstract void banned(String participant, String actor, String reason);
/** /**
* Called when an administrator grants a user membership to the room. This means that the user * Called when an administrator grants a user membership to the room. This means that the user
@ -166,8 +170,10 @@ public interface ParticipantStatusListener {
* Called when a participant changed his/her nickname in the room. The new participant's * Called when a participant changed his/her nickname in the room. The new participant's
* nickname will be informed with the next available presence. * nickname will be informed with the next available presence.
* *
* @param nickname the old nickname that the participant decided to change. * @param participant the participant that was revoked administrator privileges
* (e.g. room@conference.jabber.org/nick).
* @param newNickname the new nickname that the participant decided to use.
*/ */
public abstract void nicknameChanged(String nickname); public abstract void nicknameChanged(String participant, String newNickname);
} }

View file

@ -681,8 +681,8 @@ public class MultiUserChatTest extends SmackTestCase {
muc3.join("testbot3"); muc3.join("testbot3");
// User3 will lister for user2's "kicking" // User3 will lister for user2's "kicking"
muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() { muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() {
public void kicked(String participant) { public void kicked(String participant, String actor, String reason) {
super.kicked(participant); super.kicked(participant, actor, reason);
answer[2] = participant; answer[2] = participant;
} }
}); });
@ -758,8 +758,8 @@ public class MultiUserChatTest extends SmackTestCase {
muc3.join("testbot3"); muc3.join("testbot3");
// User3 will lister for user2's "banning" // User3 will lister for user2's "banning"
muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() { muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() {
public void banned(String participant) { public void banned(String participant, String actor, String reason) {
super.banned(participant); super.banned(participant, actor, reason);
answer[2] = participant; answer[2] = participant;
} }
}); });