From 075db51590bbbb4063ab6250c6789807b5e068c2 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Tue, 11 Jan 2005 17:35:41 +0000 Subject: [PATCH] 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 --- .../smackx/muc/InvitationListener.java | 10 +++--- .../smackx/muc/MultiUserChat.java | 34 ++++++++++++------- .../smackx/muc/MultiUserChatTest.java | 9 ++--- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/source/org/jivesoftware/smackx/muc/InvitationListener.java b/source/org/jivesoftware/smackx/muc/InvitationListener.java index 139ff0638..eeb814e7a 100644 --- a/source/org/jivesoftware/smackx/muc/InvitationListener.java +++ b/source/org/jivesoftware/smackx/muc/InvitationListener.java @@ -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); } diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index cc42b3156..cdcd2e115 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -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.

+ * + * 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); } }; }; diff --git a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java index f17fd3e96..9851b2357 100644 --- a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java +++ b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java @@ -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; } });