1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-30 07:52:06 +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; package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.XMPPConnection; 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. * 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 inviter the inviter that sent the invitation. (e.g. crone1@shakespeare.lit).
* @param reason the reason why the inviter sent the invitation. * @param reason the reason why the inviter sent the invitation.
* @param password the password to use when joining the room. * @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( public abstract void invitationReceived(XMPPConnection conn, String room, String inviter, String reason,
XMPPConnection conn, String password, Message message);
String room,
String inviter,
String reason,
String password);
} }

View file

@ -639,8 +639,23 @@ public class MultiUserChat {
* @param reason the reason why the user is being invited. * @param reason the reason why the user is being invited.
*/ */
public void invite(String user, String reason) { 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 // 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 // Create the MUCUser packet that will include the invitation
MUCUser mucUser = new MUCUser(); MUCUser mucUser = new MUCUser();
@ -652,7 +667,6 @@ public class MultiUserChat {
message.addExtension(mucUser); message.addExtension(mucUser);
connection.sendPacket(message); connection.sendPacket(message);
} }
/** /**
@ -2465,18 +2479,15 @@ public class MultiUserChat {
/** /**
* Fires invitation listeners. * Fires invitation listeners.
*/ */
private void fireInvitationListeners( private void fireInvitationListeners(String room, String inviter, String reason, String password,
String room, Message message) {
String inviter,
String reason,
String password) {
InvitationListener[] listeners = null; InvitationListener[] listeners = null;
synchronized (invitationsListeners) { synchronized (invitationsListeners) {
listeners = new InvitationListener[invitationsListeners.size()]; listeners = new InvitationListener[invitationsListeners.size()];
invitationsListeners.toArray(listeners); invitationsListeners.toArray(listeners);
} }
for (int i = 0; i < listeners.length; i++) { 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 // Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null) { if (mucUser.getInvite() != null) {
// Fire event for invitation listeners // Fire event for invitation listeners
fireInvitationListeners( fireInvitationListeners(packet.getFrom(), mucUser.getInvite().getFrom(),
packet.getFrom(), mucUser.getInvite().getReason(), mucUser.getPassword(), (Message) packet);
mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(),
mucUser.getPassword());
} }
}; };
}; };

View file

@ -280,7 +280,8 @@ public class MultiUserChatTest extends SmackTestCase {
String room, String room,
String inviter, String inviter,
String reason, String reason,
String password) { String password,
Message message) {
// Indicate that the invitation was received // Indicate that the invitation was received
answer[0] = reason; answer[0] = reason;
// Reject the invitation // Reject the invitation