/**
     * <code>receivedPacket</code> of PacketListener handler, this filters for jabber:iq:auth
     * extensions, then broadcasts those events on a special RosterListener interface.
     *
     * @param p incoming <code>PacketEvent</code>
     */
    public void receivedPacket(PacketEvent p) {
      if (!(p.getPacket() instanceof InfoQuery)) return;
      Enumeration e = ((InfoQuery) p.getPacket()).Extensions();
      Extension ext;
      if ((e == null) || (!e.hasMoreElements())) return;

      ext = (Extension) e.nextElement();

      if (!(ext instanceof Roster)) return;

      // TODO: add code to modify current roster image based on
      // new data. Replacement is basically shown by if the type is not
      // 'result' of the IQ
      Roster rext = (Roster) ext;

      if (((InfoQuery) p.getPacket()).getType().equals("result")) {
        // the results of a get will be the results of a full fetch
        Enumeration enumx = rext.items();
        currentRoster.clear();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }
        fireUserRosterReplaced(rext);
      } else {
        Enumeration enumx = rext.items();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }

        fireUserRosterChanged(rext);
      }
    }
 @Override
 public int compare(RosterItem rosterItem1, RosterItem rosterItem2) {
   int presenceOrder = this.presenceComparator.compare(rosterItem1, rosterItem2);
   if (presenceOrder == 0) {
     return rosterItem1.getName().compareTo(rosterItem2.getName());
   } else {
     return presenceOrder;
   }
 }
Example #3
0
  /**
   * Removes the entire roster of a given user. This is necessary when a user account is being
   * deleted from the server.
   *
   * @param user the user.
   */
  public void deleteRoster(JID user) {
    try {
      String username = user.getNode();
      // Get the roster of the deleted user
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(username);
      if (roster == null) {
        // Not in cache so load a new one:
        roster = new Roster(username);
      }
      // Remove each roster item from the user's roster
      for (RosterItem item : roster.getRosterItems()) {
        try {
          roster.deleteRosterItem(item.getJid(), false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
      // Remove the cached roster from memory
      CacheManager.getCache("username2roster").remove(username);

      // Get the rosters that have a reference to the deleted user
      RosterItemProvider rosteItemProvider = RosterItemProvider.getInstance();
      Iterator<String> usernames = rosteItemProvider.getUsernames(user.toBareJID());
      while (usernames.hasNext()) {
        username = usernames.next();
        // Get the roster that has a reference to the deleted user
        roster = (Roster) CacheManager.getCache("username2roster").get(username);
        if (roster == null) {
          // Not in cache so load a new one:
          roster = new Roster(username);
        }
        // Remove the deleted user reference from this roster
        try {
          roster.deleteRosterItem(user, false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
    } catch (UnsupportedOperationException e) {
      // Do nothing
    }
  }
Example #4
0
 @Override
 public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
   RosterItem item = (RosterItem) parent.getItemAtPosition(position);
   if (item.isGroup()) {
     String name = item.getName();
     if (!name.equals(getString(R.string.Nogroup))
         && !name.equals(getString(R.string.SelfGroup))
         && !name.equals(getString(R.string.MUC))
         && !name.equals(getString(R.string.Privates))
         && !name.equals(getString(R.string.ActiveChats)))
       RosterDialogs.renameGroupDialog(this, item.getAccount(), item.getName());
   } else if (item.isAccount()) {
     RosterDialogs.AccountMenuDialog(this, item);
   } else if (item.isEntry()) {
     String j = item.getEntry().getUser();
     if (!service.getPrivateMessages(item.getAccount()).contains(j))
       RosterDialogs.ContactMenuDialog(this, item);
     else RosterDialogs.PrivateMenuDialog(this, item);
   } else if (item.isSelf()) {
     RosterDialogs.SelfContactMenuDialog(this, item);
   } else if (item.isMuc()) {
     MucDialogs.roomMenu(this, item.getAccount(), item.getName());
   }
   return true;
 }
Example #5
0
  @Override
  public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    RosterItem item = (RosterItem) parent.getItemAtPosition(position);
    String name = item.getName();
    String account = item.getAccount();

    if (item.isGroup() || item.isAccount()) {
      if (item.isCollapsed()) {
        while (service.getCollapsedGroups().contains(name))
          service.getCollapsedGroups().remove(name);
        item.setCollapsed(false);
      } else {
        service.getCollapsedGroups().add(name);
        item.setCollapsed(true);
      }
      updateList();
    } else if (item.isEntry() || item.isSelf()) {
      RosterEntry re = item.getEntry();
      String jid = re.getUser();
      Intent i = new Intent(this, Chat.class);
      i.putExtra("account", account);
      i.putExtra("jid", jid);
      startActivity(i);
    } else if (item.isMuc()) {
      Intent i = new Intent(this, Chat.class);
      i.putExtra("account", account);
      i.putExtra("jid", item.getName());
      startActivity(i);
    }
  }