mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-27 00:32:07 +01:00
Added notifications of occupant joining and leaving the room. SMACK-38
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2437 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
81d647af56
commit
d2187b7374
4 changed files with 135 additions and 0 deletions
|
@ -31,6 +31,12 @@ package org.jivesoftware.smackx.muc;
|
||||||
*/
|
*/
|
||||||
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
|
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
|
||||||
|
|
||||||
|
public void joined(String participant) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void left(String participant) {
|
||||||
|
}
|
||||||
|
|
||||||
public void kicked(String participant) {
|
public void kicked(String participant) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2014,6 +2014,12 @@ public class MultiUserChat {
|
||||||
isUserStatusModification,
|
isUserStatusModification,
|
||||||
from);
|
from);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// A new occupant has joined the room
|
||||||
|
if (!isUserStatusModification) {
|
||||||
|
fireParticipantStatusListeners("joined", from);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (presence.getType() == Presence.Type.UNAVAILABLE) {
|
else if (presence.getType() == Presence.Type.UNAVAILABLE) {
|
||||||
synchronized (occupantsMap) {
|
synchronized (occupantsMap) {
|
||||||
|
@ -2027,6 +2033,11 @@ public class MultiUserChat {
|
||||||
presence.getFrom().equals(myRoomJID),
|
presence.getFrom().equals(myRoomJID),
|
||||||
mucUser,
|
mucUser,
|
||||||
from);
|
from);
|
||||||
|
} else {
|
||||||
|
// An occupant has left the room
|
||||||
|
if (!isUserStatusModification) {
|
||||||
|
fireParticipantStatusListeners("left", from);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,23 @@ package org.jivesoftware.smackx.muc;
|
||||||
*/
|
*/
|
||||||
public interface ParticipantStatusListener {
|
public interface ParticipantStatusListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a new room occupant has joined the room.
|
||||||
|
*
|
||||||
|
* @param participant the participant that has just joined the room
|
||||||
|
* (e.g. room@conference.jabber.org/nick).
|
||||||
|
*/
|
||||||
|
public abstract void joined(String participant);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a room occupant has left the room on its own. This means that the occupant was
|
||||||
|
* neither kicked nor banned from the room.
|
||||||
|
*
|
||||||
|
* @param participant the participant that has left the room on its own.
|
||||||
|
* (e.g. room@conference.jabber.org/nick).
|
||||||
|
*/
|
||||||
|
public abstract void left(String participant);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a room participant has been kicked from the room. This means that the kicked
|
* Called when a room participant has been kicked from the room. This means that the kicked
|
||||||
* participant is no longer participating in the room.
|
* participant is no longer participating in the room.
|
||||||
|
|
|
@ -1503,6 +1503,107 @@ public class MultiUserChatTest extends SmackTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that ParticipantStatusListener is receiving joining and leaving events correctly.
|
||||||
|
*/
|
||||||
|
public void testJoinLeftEvents() {
|
||||||
|
final String[] answer = new String[8];
|
||||||
|
try {
|
||||||
|
// User1 will listen for occupants joining and leaving the room
|
||||||
|
muc.addParticipantStatusListener(new DefaultParticipantStatusListener() {
|
||||||
|
public void joined(String participant) {
|
||||||
|
super.joined(participant);
|
||||||
|
if ((room + "/testbot2").equals(participant)) {
|
||||||
|
answer[0] = participant;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answer[1] = participant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void left(String participant) {
|
||||||
|
super.left(participant);
|
||||||
|
if ((room + "/testbot2").equals(participant)) {
|
||||||
|
answer[2] = participant;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answer[3] = participant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// User2 joins the new room
|
||||||
|
MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
|
||||||
|
// User2 will listen for User3 joining and leaving the room
|
||||||
|
muc2.addParticipantStatusListener(new DefaultParticipantStatusListener() {
|
||||||
|
public void joined(String participant) {
|
||||||
|
super.joined(participant);
|
||||||
|
if ((room + "/testbot").equals(participant)) {
|
||||||
|
answer[4] = participant;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answer[5] = participant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void left(String participant) {
|
||||||
|
super.left(participant);
|
||||||
|
if ((room + "/testbot").equals(participant)) {
|
||||||
|
answer[6] = participant;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answer[7] = participant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
muc2.join("testbot2");
|
||||||
|
|
||||||
|
// User3 joins the new room
|
||||||
|
MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
|
||||||
|
muc3.join("testbot3");
|
||||||
|
|
||||||
|
// User3 leaves the room
|
||||||
|
muc3.leave();
|
||||||
|
// User2 leaves the room
|
||||||
|
muc2.leave();
|
||||||
|
|
||||||
|
// Check that ParticipantStatusListener is working OK
|
||||||
|
assertEquals(
|
||||||
|
"User1 didn't receive the event of User2 joining the room",
|
||||||
|
room + "/testbot2",
|
||||||
|
answer[0]);
|
||||||
|
assertEquals(
|
||||||
|
"User1 didn't receive the event of User3 joining the room",
|
||||||
|
room + "/testbot3",
|
||||||
|
answer[1]);
|
||||||
|
assertEquals(
|
||||||
|
"User1 didn't receive the event of User2 leaving the room",
|
||||||
|
room + "/testbot2",
|
||||||
|
answer[2]);
|
||||||
|
assertEquals(
|
||||||
|
"User1 didn't receive the event of User3 leaving the room",
|
||||||
|
room + "/testbot3",
|
||||||
|
answer[3]);
|
||||||
|
assertEquals(
|
||||||
|
"User2 didn't receive the event of User1 joining the room",
|
||||||
|
room + "/testbot",
|
||||||
|
answer[4]);
|
||||||
|
assertEquals(
|
||||||
|
"User2 didn't receive the event of User3 joining the room",
|
||||||
|
room + "/testbot3",
|
||||||
|
answer[5]);
|
||||||
|
assertNull(
|
||||||
|
"User2 received the event of User1 leaving the room",
|
||||||
|
answer[6]);
|
||||||
|
assertEquals(
|
||||||
|
"User2 didn't receive the event of User3 leaving the room",
|
||||||
|
room + "/testbot3",
|
||||||
|
answer[7]);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void makeRoomModerated() throws XMPPException {
|
private void makeRoomModerated() throws XMPPException {
|
||||||
// User1 (which is the room owner) converts the instant room into a moderated room
|
// User1 (which is the room owner) converts the instant room into a moderated room
|
||||||
Form form = muc.getConfigurationForm();
|
Form form = muc.getConfigurationForm();
|
||||||
|
|
Loading…
Reference in a new issue