/**
   * Subscribes this provider as interested in receiving notifications for new mail messages from
   * Google mail services such as Gmail or Google Apps.
   */
  private void subscribeForGmailNotifications() {
    // first check support for the notification service
    String accountIDService = jabberProvider.getAccountID().getService();
    boolean notificationsAreSupported =
        jabberProvider.isFeatureSupported(accountIDService, NewMailNotificationIQ.NAMESPACE);

    if (!notificationsAreSupported) {
      if (logger.isDebugEnabled())
        logger.debug(
            accountIDService
                + " does not seem to provide a Gmail notification "
                + " service so we won't be trying to subscribe for it");
      return;
    }

    if (logger.isDebugEnabled())
      logger.debug(
          accountIDService
              + " seems to provide a Gmail notification "
              + " service so we will try to subscribe for it");

    ProviderManager providerManager = ProviderManager.getInstance();

    providerManager.addIQProvider(
        MailboxIQ.ELEMENT_NAME, MailboxIQ.NAMESPACE, new MailboxIQProvider());
    providerManager.addIQProvider(
        NewMailNotificationIQ.ELEMENT_NAME,
        NewMailNotificationIQ.NAMESPACE,
        new NewMailNotificationProvider());

    Connection connection = jabberProvider.getConnection();

    connection.addPacketListener(new MailboxIQListener(), new PacketTypeFilter(MailboxIQ.class));
    connection.addPacketListener(
        new NewMailNotificationListener(), new PacketTypeFilter(NewMailNotificationIQ.class));

    if (opSetPersPresence.getCurrentStatusMessage().equals(JabberStatusEnum.OFFLINE)) return;

    // create a query with -1 values for newer-than-tid and
    // newer-than-time attributes
    MailboxQueryIQ mailboxQuery = new MailboxQueryIQ();

    if (logger.isTraceEnabled())
      logger.trace(
          "sending mailNotification for acc: "
              + jabberProvider.getAccountID().getAccountUniqueID());
    jabberProvider.getConnection().sendPacket(mailboxQuery);
  }
Example #2
0
  /**
   * Creates a new workgroup instance using the specified workgroup JID (eg
   * [email protected]) and XMPP connection. The connection must have undergone a
   * successful login before being used to construct an instance of this class.
   *
   * @param workgroupJID the JID of the workgroup.
   * @param connection an XMPP connection which must have already undergone a successful login.
   */
  public Workgroup(String workgroupJID, Connection connection) {
    // Login must have been done before passing in connection.
    if (!connection.isAuthenticated()) {
      throw new IllegalStateException("Must login to server before creating workgroup.");
    }

    this.workgroupJID = workgroupJID;
    this.connection = connection;
    inQueue = false;
    invitationListeners = new ArrayList<WorkgroupInvitationListener>();
    queueListeners = new ArrayList<QueueListener>();

    // Register as a queue listener for internal usage by this instance.
    addQueueListener(
        new QueueListener() {
          public void joinedQueue() {
            inQueue = true;
          }

          public void departedQueue() {
            inQueue = false;
            queuePosition = -1;
            queueRemainingTime = -1;
          }

          public void queuePositionUpdated(int currentPosition) {
            queuePosition = currentPosition;
          }

          public void queueWaitTimeUpdated(int secondsRemaining) {
            queueRemainingTime = secondsRemaining;
          }
        });

    /**
     * Internal handling of an invitation.Recieving an invitation removes the user from the queue.
     */
    MultiUserChat.addInvitationListener(
        connection,
        new org.jivesoftware.smackx.muc.InvitationListener() {
          public void invitationReceived(
              Connection conn,
              String room,
              String inviter,
              String reason,
              String password,
              Message message) {
            inQueue = false;
            queuePosition = -1;
            queueRemainingTime = -1;
          }
        });

    // Register a packet listener for all the messages sent to this client.
    PacketFilter typeFilter = new PacketTypeFilter(Message.class);

    connection.addPacketListener(
        new PacketListener() {
          public void processPacket(Packet packet) {
            handlePacket(packet);
          }
        },
        typeFilter);
  }