@Override public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider) { LinkedList<ChatRoomSourceContact> tmpContactResults; synchronized (contactResults) { tmpContactResults = new LinkedList<ChatRoomSourceContact>(contactResults); for (ChatRoomSourceContact contact : tmpContactResults) { if (contact.getProvider().equals(provider.getProtocolProvider())) { contactResults.remove(contact); fireContactRemoved(contact); } } } }
/** * 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); } } }
/** * Returns the index of the contact in the contact results list. * * @param contact the contact. * @return the index of the contact in the contact results list. */ public synchronized int indexOf(ChatRoomSourceContact contact) { Iterator<ChatRoomSourceContact> it = contactResults.iterator(); int i = 0; while (it.hasNext()) { if (contact.equals(it.next())) { return i; } i++; } return -1; }
/** * Indicates that a change has occurred in the chat room data list. * * @param evt the event that describes the change. */ @Override public void contentChanged(final ChatRoomListChangeEvent evt) { ChatRoomWrapper chatRoom = evt.getSourceChatRoom(); switch (evt.getEventID()) { case ChatRoomListChangeEvent.CHAT_ROOM_ADDED: addChatRoom(chatRoom.getChatRoom(), false, chatRoom.isAutojoin()); break; case ChatRoomListChangeEvent.CHAT_ROOM_REMOVED: LinkedList<ChatRoomSourceContact> tmpContactResults; synchronized (contactResults) { tmpContactResults = new LinkedList<ChatRoomSourceContact>(contactResults); for (ChatRoomSourceContact contact : tmpContactResults) { if (contactEqualsChatRoom(contact, chatRoom)) { contactResults.remove(contact); fireContactRemoved(contact); break; } } } break; case ChatRoomListChangeEvent.CHAT_ROOM_CHANGED: synchronized (contactResults) { for (ChatRoomSourceContact contact : contactResults) { if (contactEqualsChatRoom(contact, chatRoom.getChatRoom())) { if (chatRoom.isAutojoin() != contact.isAutoJoin()) { contact.setAutoJoin(chatRoom.isAutojoin()); fireContactChanged(contact); } break; } } } break; default: break; } }
/** * Test equality of contact to chat room wrapper. This method does not rely on a chat room * instance, since that may not be available in case of removal. * * @param contact the contact * @param chatRoomWrapper the chat room wrapper * @return returns <tt>true</tt> if they are equal, or <tt>false</tt> if they are different. */ private boolean contactEqualsChatRoom( final ChatRoomSourceContact contact, final ChatRoomWrapper chatRoomWrapper) { return contact.getProvider() == chatRoomWrapper.getParentProvider().getProtocolProvider() && contact.getContactAddress().equals(chatRoomWrapper.getChatRoomID()); }
/** * 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()); }