/** * Handles chat room presence status updates. * * @param evt the <tt>LocalUserChatRoomPresenceChangeEvent</tt> instance containing the chat room * and the type, and reason of the change */ @Override public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt) { ChatRoom sourceChatRoom = evt.getChatRoom(); String eventType = evt.getEventType(); boolean existingContact = false; ChatRoomSourceContact foundContact = null; synchronized (contactResults) { for (ChatRoomSourceContact contact : contactResults) { if (contactEqualsChatRoom(contact, sourceChatRoom)) { existingContact = true; foundContact = contact; contactResults.remove(contact); break; } } } if (LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED.equals(eventType)) { if (existingContact) { foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_ONLINE); synchronized (contactResults) { contactResults.add(foundContact); } fireContactChanged(foundContact); } else { ChatRoomWrapper chatRoom = MUCActivator.getMUCService().findChatRoomWrapperFromChatRoom(sourceChatRoom); if (chatRoom != null) addChatRoom(sourceChatRoom, false, chatRoom.isAutojoin()); } } else if ((LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT.equals(eventType) || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED.equals(eventType) || LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED.equals(eventType))) { if (existingContact) { foundContact.setPresenceStatus(ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE); synchronized (contactResults) { contactResults.add(foundContact); } fireContactChanged(foundContact); } } }
/** * Adds found result to the query results. * * @param room the chat room. * @param addQueryResult indicates whether we should add the chat room to the query results or * fire an event without adding it to the results. * @param isAutoJoin the auto join state of the contact. */ private void addChatRoom(ChatRoom room, boolean addQueryResult, boolean isAutoJoin) { if (queryString == null || ((room.getName().contains(queryString) || room.getIdentifier().contains(queryString)))) { ChatRoomSourceContact contact = new ChatRoomSourceContact(room, this, isAutoJoin); synchronized (contactResults) { contactResults.add(contact); } if (addQueryResult) { addQueryResult(contact, false); } else { fireContactReceived(contact, false); } } }
/** * Adds found result to the query results. * * @param pps the protocol provider associated with the found chat room. * @param chatRoomName the name of the chat room. * @param chatRoomID the id of the chat room. * @param addQueryResult indicates whether we should add the chat room to the query results or * fire an event without adding it to the results. * @param isAutoJoin the auto join state of the contact. */ private void addChatRoom( ProtocolProviderService pps, String chatRoomName, String chatRoomID, boolean addQueryResult, boolean isAutoJoin) { if (queryString == null || ((chatRoomName.contains(queryString) || chatRoomID.contains(queryString)))) { ChatRoomSourceContact contact = new ChatRoomSourceContact(chatRoomName, chatRoomID, this, pps, isAutoJoin); synchronized (contactResults) { contactResults.add(contact); } if (addQueryResult) { addQueryResult(contact, false); } else { fireContactReceived(contact, false); } } }