/**
  * Returns the current presence of the user.
  *
  * @param user the user
  * @return the current presence of the user.
  */
 public Presence getPresence(ApnUser user) {
   if (user == null) {
     return null;
   }
   Presence presence = null;
   ClientSession session = sessionManager.getSession(user.getUsername());
   if (session != null) {
     presence = session.getPresence();
   }
   return presence;
 }
  /**
   * Broadcasts a newly created notification message to all connected users.
   *
   * @param apiKey the API key
   * @param title the title
   * @param message the message details
   * @param uri the uri
   */
  public void sendBroadcast(String apiKey, String title, String message, String uri) {
    log.debug("sendBroadcast()...");

    List<User> users = userService.getUsers();
    for (User user : users) {
      ClientSession session = sessionManager.getSession(user.getUsername());
      Random random = new Random();
      String id = Integer.toHexString(random.nextInt());
      IQ notificationIQ = createNotificationIQ(id, apiKey, title, message, uri);
      if (session != null && session.getPresence().isAvailable()) {
        notificationIQ.setTo(session.getAddress());
        session.deliver(notificationIQ);
      }

      saveNotification(id, apiKey, user.getUsername(), title, message, uri);
    }
  }
  /**
   * Sends a newly created notification message to the specific user.
   *
   * @param apiKey the API key
   * @param title the title
   * @param message the message details
   * @param uri the uri
   */
  public void sendNotifcationToUser(
      String apiKey, String username, String title, String message, String uri, boolean save) {
    log.debug("sendNotifcationToUser()...");
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    IQ notificationIQ = createNotificationIQ(id, apiKey, title, message, uri);
    ClientSession session = sessionManager.getSession(username);
    if (session != null) {
      if (session.getPresence().isAvailable()) {
        notificationIQ.setTo(session.getAddress());
        session.deliver(notificationIQ);
      }
    }

    try {
      User user = userService.getUserByUsername(username);
      if (user != null && save) {
        saveNotification(id, apiKey, username, title, message, uri);
      }
    } catch (UserNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }