diff options
3 files changed, 92 insertions, 31 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java index 07d6f5b..94eb2eb 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java @@ -504,6 +504,13 @@ public class ChatRoomJabberImpl } else { + this.provider.getConnection().addPacketListener( + new PresenceListeners(this), + new AndFilter( + new FromMatchesFilter( + multiUserChat.getRoom() + "/" + nickname), + new PacketTypeFilter( + org.jivesoftware.smack.packet.Presence.class))); if(password == null) multiUserChat.join(nickname); else @@ -2324,6 +2331,62 @@ public class ChatRoomJabberImpl { return multiUserChat; } + + /** + * Listens for presence packets. + */ + private class PresenceListeners + implements PacketListener + { + /** + * Chat room associated with the listener. + */ + private ChatRoom chatRoom; + + /** + * Creates an instance of a listener of presence packets. + * + * @param chatRoom the chat room associated with the listener + */ + public PresenceListeners(ChatRoom chatRoom) + { + super(); + this.chatRoom = chatRoom; + } + + /** + * Process incoming presence packet, checks if the room is created and + * finishes the creation of the room. + * @param packet the incoming packet. + */ + @Override + public void processPacket(Packet packet) + { + Presence presence = (Presence) packet; + if (presence == null || presence.getError() != null) + return; + + MUCUser mucUser = getMUCUserExtension(packet); + if (mucUser != null && mucUser.getStatus() != null) { + if ("201".equals(mucUser.getStatus().getCode())) { + try + { + multiUserChat.sendConfigurationForm( + new Form(Form.TYPE_SUBMIT)); + } catch (XMPPException e) + { + logger.error("Failed to send config form.", e); + } + opSetMuc.addSmackInvitationRejectionListener(multiUserChat, + chatRoom); + setLocalUserRole(ChatRoomMemberRole.MODERATOR); + provider.getConnection().removePacketListener(this); + } + } + } + + + } /** * Listens for rejection message and delivers system message when received. diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java index 218d9b5..a5b877e 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java @@ -75,6 +75,21 @@ public class OperationSetMultiUserChatJabberImpl } /** + * Add SmackInvitationRejectionListener to <tt>MultiUserChat</tt> instance + * which will dispatch all rejection events. + * + * @param muc the smack MultiUserChat instance that we're going to wrap our + * chat room around. + * @param chatRoom the associated chat room instance + */ + public void addSmackInvitationRejectionListener(MultiUserChat muc, + ChatRoom chatRoom) + { + muc.addInvitationRejectionListener( + new SmackInvitationRejectionListener(chatRoom)); + } + + /** * Creates a room with the named <tt>roomName</tt> and according to the * specified <tt>roomProperties</tt> on the server that this protocol * provider is currently connected to. @@ -168,21 +183,19 @@ public class OperationSetMultiUserChatJabberImpl // Add the contained in this class SmackInvitationRejectionListener // which will dispatch all rejection events to the // ChatRoomInvitationRejectionListener. - muc.addInvitationRejectionListener( - new SmackInvitationRejectionListener(chatRoom)); + addSmackInvitationRejectionListener(muc, chatRoom); return chatRoom; } } /** - * Returns a reference to a chatRoom named <tt>roomName</tt> or null - * if that room does not exist. + * Returns a reference to a chatRoom named <tt>roomName</tt>. If the room + * doesn't exists in the cache it creates it. * * @param roomName the name of the <tt>ChatRoom</tt> that we're looking * for. - * @return the <tt>ChatRoom</tt> named <tt>roomName</tt> if it exists, null - * otherwise. + * @return the <tt>ChatRoom</tt> named <tt>roomName</tt> * @throws OperationFailedException if an error occurs while trying to * discover the room on the server. * @throws OperationNotSupportedException if the server does not support @@ -200,26 +213,12 @@ public class OperationSetMultiUserChatJabberImpl if (room != null) return room; - try - { - // throws Exception if room does not exist - // do not use MultiUserChat.getRoomInfo as there is a bug which - // throws NPE - ServiceDiscoveryManager.getInstanceFor(getXmppConnection()). - discoverInfo(canonicalRoomName); + MultiUserChat muc + = new MultiUserChat(getXmppConnection(), canonicalRoomName); - MultiUserChat muc - = new MultiUserChat(getXmppConnection(), canonicalRoomName); - - room = new ChatRoomJabberImpl(muc, jabberProvider); - chatRoomCache.put(canonicalRoomName, room); - return room; - } - catch (XMPPException e) - { - // room not found - return null; - } + room = new ChatRoomJabberImpl(muc, jabberProvider); + chatRoomCache.put(canonicalRoomName, room); + return room; } /** @@ -597,11 +596,6 @@ public class OperationSetMultiUserChatJabberImpl try { chatRoom = (ChatRoomJabberImpl) findRoom(room); - if (chatRoom == null) - { - MultiUserChat muc = new MultiUserChat(conn, room); - chatRoom = new ChatRoomJabberImpl(muc, jabberProvider); - } if (password != null) fireInvitationEvent( chatRoom, inviter, reason, password.getBytes()); diff --git a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java index a36ec30..c0c0053 100644 --- a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java +++ b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java @@ -529,6 +529,10 @@ public class TestOperationSetMultiUserChat2 opSet1Room.join(); ChatRoom foundRoom = null; + /* + //findRoom always returns ChatRoom instance. If it doesn't exists in + //the cache it creates an instance of ChatRoom. + try { foundRoom = opSetMUC1.findRoom("WhoCreatedThatRoom"); @@ -539,7 +543,7 @@ public class TestOperationSetMultiUserChat2 } assertNull("wasnt expecting to find the room named " + "'WhoCreatedThatRoom' on server", foundRoom); - +*/ // to find the existing room created with opSetMUC1, // we will use opSetMUC2 to be sure the room will not be retrieved from // opSetMUC1 cache |