Exemple #1
0
  /**
   * Creates an instance of <tt>ChatRoomQuery</tt> by specifying the parent contact source, the
   * query string to match and the maximum result contacts to return.
   *
   * @param queryString the query string to match
   * @param contactSource the parent contact source
   */
  public ChatRoomQuery(String queryString, ChatRoomContactSourceService contactSource) {
    super(
        contactSource,
        Pattern.compile(queryString, Pattern.CASE_INSENSITIVE | Pattern.LITERAL),
        true);
    this.queryString = queryString;

    mucService = MUCActivator.getMUCService();
  }
Exemple #2
0
  /** Adds listeners for the query */
  private void initListeners() {
    for (ProtocolProviderService pps : MUCActivator.getChatRoomProviders()) {
      addQueryToProviderPresenceListeners(pps);
    }

    mucService.addChatRoomListChangeListener(this);
    mucService.addChatRoomProviderWrapperListener(this);
    protolProviderRegistrationListener = new ProtocolProviderRegListener();
    MUCActivator.bundleContext.addServiceListener(protolProviderRegistrationListener);
  }
Exemple #3
0
 /** Clears any listener we used. */
 private void clearListeners() {
   mucService.removeChatRoomListChangeListener(this);
   mucService.removeChatRoomProviderWrapperListener(this);
   if (protolProviderRegistrationListener != null)
     MUCActivator.bundleContext.removeServiceListener(protolProviderRegistrationListener);
   protolProviderRegistrationListener = null;
   for (ProtocolProviderService pps : MUCActivator.getChatRoomProviders()) {
     removeQueryFromProviderPresenceListeners(pps);
   }
 }
Exemple #4
0
  /**
   * 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);
      }
    }
  }