/** * Called to accept an incoming invitation. Adds the invitation chat room to the list of chat * rooms and joins it. * * @param invitation the invitation to accept. */ public void acceptInvitation(ChatRoomInvitation invitation) { ChatRoom chatRoom = invitation.getTargetChatRoom(); byte[] password = invitation.getChatRoomPassword(); String nickName = chatRoom.getParentProvider().getAccountID().getUserID(); joinChatRoom(chatRoom, nickName, password); }
/** * Searches for chat room wrapper in chat room list by chat room. * * @param chatRoom the chat room. * @param create if <tt>true</tt> and the chat room wrapper is not found new chatRoomWrapper is * created. * @return found chat room wrapper or the created chat room wrapper. */ @Override public ChatRoomWrapper getChatRoomWrapperByChatRoom(ChatRoom chatRoom, boolean create) { ChatRoomWrapper chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom); if ((chatRoomWrapper == null) && create) { ChatRoomProviderWrapper parentProvider = chatRoomList.findServerWrapperFromProvider(chatRoom.getParentProvider()); chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom); chatRoomList.addChatRoom(chatRoomWrapper); } return chatRoomWrapper; }
/** * Extract values from <tt>EventObject</tt>. * * @param source */ public void update(EventObject source) { this.eventObject = source; if (source instanceof MessageDeliveredEvent) { MessageDeliveredEvent e = (MessageDeliveredEvent) source; this.contact = e.getDestinationContact(); this.address = contact.getAddress(); this.ppService = contact.getProtocolProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof MessageReceivedEvent) { MessageReceivedEvent e = (MessageReceivedEvent) source; this.contact = e.getSourceContact(); this.address = contact.getAddress(); this.ppService = contact.getProtocolProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof ChatRoomMessageDeliveredEvent) { ChatRoomMessageDeliveredEvent e = (ChatRoomMessageDeliveredEvent) source; this.room = e.getSourceChatRoom(); this.address = room.getIdentifier(); this.ppService = room.getParentProvider(); this.timestamp = e.getTimestamp(); } else if (source instanceof ChatRoomMessageReceivedEvent) { ChatRoomMessageReceivedEvent e = (ChatRoomMessageReceivedEvent) source; this.room = e.getSourceChatRoom(); this.address = room.getIdentifier(); this.ppService = room.getParentProvider(); this.timestamp = e.getTimestamp(); } }
/** * Joins the given chat room and manages all the exceptions that could occur during the join * process. * * @param chatRoom the chat room to join * @param nickname the nickname we're using to join * @param password the password we're using to join */ public void joinChatRoom(ChatRoom chatRoom, String nickname, byte[] password) { ChatRoomWrapper chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom); if (chatRoomWrapper == null) { ChatRoomProviderWrapper parentProvider = chatRoomList.findServerWrapperFromProvider(chatRoom.getParentProvider()); chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom); chatRoomList.addChatRoom(chatRoomWrapper); fireChatRoomListChangedEvent(chatRoomWrapper, ChatRoomListChangeEvent.CHAT_ROOM_ADDED); } this.joinChatRoom(chatRoomWrapper, nickname, password); }
/** * Joins the room with the given name though the given chat room provider. * * @param chatRoomName the name of the room to join. * @param chatRoomProvider the chat room provider to join through. */ public void joinChatRoom(String chatRoomName, ChatRoomProviderWrapper chatRoomProvider) { OperationSetMultiUserChat groupChatOpSet = chatRoomProvider.getProtocolProvider().getOperationSet(OperationSetMultiUserChat.class); ChatRoom chatRoom = null; try { chatRoom = groupChatOpSet.findRoom(chatRoomName); } catch (Exception e) { if (logger.isTraceEnabled()) logger.trace("Un exception occurred while searching for room:" + chatRoomName, e); } if (chatRoom != null) { ChatRoomWrapper chatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom); if (chatRoomWrapper == null) { ChatRoomProviderWrapper parentProvider = chatRoomList.findServerWrapperFromProvider(chatRoom.getParentProvider()); chatRoomWrapper = new ChatRoomWrapperImpl(parentProvider, chatRoom); chatRoomList.addChatRoom(chatRoomWrapper); fireChatRoomListChangedEvent(chatRoomWrapper, ChatRoomListChangeEvent.CHAT_ROOM_ADDED); } joinChatRoom(chatRoomWrapper); } else MUCActivator.getAlertUIService() .showAlertDialog( MUCActivator.getResources().getI18NString("service.gui.ERROR"), MUCActivator.getResources() .getI18NString( "service.gui.CHAT_ROOM_NOT_EXIST", new String[] { chatRoomName, chatRoomProvider.getProtocolProvider().getAccountID().getService() })); }
/** * Test equality of contact to chat room. This test recognizes that chat rooms may have equal * names but connected to different accounts. * * @param contact the contact * @param chatRoom the chat room * @return returns <tt>true</tt> if they are equal, or <tt>false</tt> if they are different */ private boolean contactEqualsChatRoom( final ChatRoomSourceContact contact, final ChatRoom chatRoom) { return contact.getProvider() == chatRoom.getParentProvider() && chatRoom.getIdentifier().equals(contact.getContactAddress()); }