From 6ef4e9713124d890f1f7f0d2ecd23d8848f16b81 Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Fri, 19 Jul 2013 15:56:54 +0300 Subject: [PATCH] Removes unnecessary disco info sent before joinning the room. --- .../protocol/jabber/ChatRoomJabberImpl.java | 63 +++++++++++++++++++ .../OperationSetMultiUserChatJabberImpl.java | 47 +++++++------- 2 files changed, 84 insertions(+), 26 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 07d6f5b3f..2f4193d57 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 void joinAs(String nickname, byte[] password) } else { + this.provider.getConnection().addPacketListener( + new PresenceListeners(this), + new AndFilter( + new FromMatchesFilter( + multiUserChat.getRoom() + "/" + this.nickname), + new PacketTypeFilter( + org.jivesoftware.smack.packet.Presence.class))); if(password == null) multiUserChat.join(nickname); else @@ -2324,6 +2331,62 @@ MultiUserChat getMultiUserChat() { 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 218d9b5c2..bd198d795 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetMultiUserChatJabberImpl.java @@ -74,6 +74,21 @@ public class OperationSetMultiUserChatJabberImpl presenceOpSet.addSubscriptionListener(this); } + /** + * Add SmackInvitationRejectionListener to MultiUserChat 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 roomName and according to the * specified roomProperties on the server that this protocol @@ -168,8 +183,7 @@ private ChatRoom createLocalChatRoomInstance(MultiUserChat muc) // 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; } @@ -200,26 +214,12 @@ public synchronized ChatRoom findRoom(String roomName) 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 +597,6 @@ public void invitationReceived(Connection conn, 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());