1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 13:07:59 +01:00

Modified to allow sending extensions when inviting a user to a room. SMACK-40

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2444 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-01-11 17:35:41 +00:00 committed by gaston
parent 1bf4d2fed2
commit 075db51590
3 changed files with 30 additions and 23 deletions

View file

@ -21,6 +21,7 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;
/**
* A listener that is fired anytime an invitation to join a MUC room is received.
@ -40,12 +41,9 @@ public interface InvitationListener {
* @param inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
* @param reason the reason why the inviter sent the invitation.
* @param password the password to use when joining the room.
* @param message the message used by the inviter to send the invitation.
*/
public abstract void invitationReceived(
XMPPConnection conn,
String room,
String inviter,
String reason,
String password);
public abstract void invitationReceived(XMPPConnection conn, String room, String inviter, String reason,
String password, Message message);
}

View file

@ -639,8 +639,23 @@ public class MultiUserChat {
* @param reason the reason why the user is being invited.
*/
public void invite(String user, String reason) {
invite(new Message(), user, reason);
}
/**
* Invites another user to the room in which one is an occupant using a given Message. The invitation
* will be sent to the room which in turn will forward the invitation to the invitee.<p>
*
* If the room is password-protected, the invitee will receive a password to use to join
* the room. If the room is members-only, the the invitee may be added to the member list.
*
* @param message the message to use for sending the invitation.
* @param user the user to invite to the room.(e.g. hecate@shakespeare.lit)
* @param reason the reason why the user is being invited.
*/
public void invite(Message message, String user, String reason) {
// TODO listen for 404 error code when inviter supplies a non-existent JID
Message message = new Message(room);
message.setTo(room);
// Create the MUCUser packet that will include the invitation
MUCUser mucUser = new MUCUser();
@ -652,7 +667,6 @@ public class MultiUserChat {
message.addExtension(mucUser);
connection.sendPacket(message);
}
/**
@ -2465,18 +2479,15 @@ public class MultiUserChat {
/**
* Fires invitation listeners.
*/
private void fireInvitationListeners(
String room,
String inviter,
String reason,
String password) {
private void fireInvitationListeners(String room, String inviter, String reason, String password,
Message message) {
InvitationListener[] listeners = null;
synchronized (invitationsListeners) {
listeners = new InvitationListener[invitationsListeners.size()];
invitationsListeners.toArray(listeners);
}
for (int i = 0; i < listeners.length; i++) {
listeners[i].invitationReceived(connection, room, inviter, reason, password);
listeners[i].invitationReceived(connection, room, inviter, reason, password, message);
}
}
@ -2507,11 +2518,8 @@ public class MultiUserChat {
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null) {
// Fire event for invitation listeners
fireInvitationListeners(
packet.getFrom(),
mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(),
mucUser.getPassword());
fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
}
};
};

View file

@ -280,18 +280,19 @@ public class MultiUserChatTest extends SmackTestCase {
String room,
String inviter,
String reason,
String password) {
// Indicate that the invitation was received
String password,
Message message) {
// Indicate that the invitation was received
answer[0] = reason;
// Reject the invitation
MultiUserChat.decline(conn, room, inviter, "I'm busy right now");
}
});
// User2 is listening to invitation rejections
// User2 is listening to invitation rejections
muc2.addInvitationRejectionListener(new InvitationRejectionListener() {
public void invitationDeclined(String invitee, String reason) {
// Indicate that the rejection was received
// Indicate that the rejection was received
answer[1] = reason;
}
});