示例#1
0
  private void syncUsers() {
    for (RosterEntry entry : conn.getRoster().getEntries()) {
      getBuddyManager()
          .storeBuddy(
              new XMPPBuddy(
                  getBuddyManager(), entry.getUser(), entry.getName(), entry.getGroups(), entry));
      // Facebook does not support presence probes in their XMPP implementation. See
      // http://developers.facebook.com/docs/chat#features
      if (!TransportType.facebook.equals(getTransport().getType())) {
        // ProbePacket probe = new ProbePacket(this.getJID()+"/"+xmppResource, entry.getUser());
        ProbePacket probe = new ProbePacket(null, entry.getUser());
        Log.debug("XMPP: Sending the following probe packet: " + probe.toXML());
        try {
          conn.sendPacket(probe);
        } catch (IllegalStateException e) {
          Log.debug("XMPP: Not connected while trying to send probe.");
        }
      }
    }

    try {
      getTransport().syncLegacyRoster(getJID(), getBuddyManager().getBuddies());
    } catch (UserNotFoundException ex) {
      Log.error("XMPP: User not found while syncing legacy roster: ", ex);
    }

    getBuddyManager().activate();

    // lets repoll the roster since smack seems to get out of sync...
    // we'll let the roster listener take care of this though.
    conn.getRoster().reload();
  }
示例#2
0
  /**
   * @see net.sf.kraken.session.TransportSession#addContact(org.xmpp.packet.JID, String,
   *     java.util.ArrayList)
   */
  @Override
  public void addContact(JID jid, String nickname, ArrayList<String> groups) {
    String mail = getTransport().convertJIDToID(jid);
    try {
      conn.getRoster().createEntry(mail, nickname, groups.toArray(new String[groups.size()]));
      RosterEntry entry = conn.getRoster().getEntry(mail);

      getBuddyManager()
          .storeBuddy(new XMPPBuddy(getBuddyManager(), mail, nickname, entry.getGroups(), entry));
    } catch (XMPPException ex) {
      Log.debug("XMPP: unable to add:" + mail);
    }
  }
示例#3
0
 /**
  * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
  */
 @Override
 public void updateContact(XMPPBuddy contact) {
   RosterEntry user2Update;
   String mail = getTransport().convertJIDToID(contact.getJID());
   user2Update = conn.getRoster().getEntry(mail);
   user2Update.setName(contact.getNickname());
   Collection<String> newgroups = contact.getGroups();
   if (newgroups == null) {
     newgroups = new ArrayList<String>();
   }
   for (RosterGroup group : conn.getRoster().getGroups()) {
     if (newgroups.contains(group.getName())) {
       if (!group.contains(user2Update)) {
         try {
           group.addEntry(user2Update);
         } catch (XMPPException e) {
           Log.debug("XMPP: Unable to add roster item to group.");
         }
       }
       newgroups.remove(group.getName());
     } else {
       if (group.contains(user2Update)) {
         try {
           group.removeEntry(user2Update);
         } catch (XMPPException e) {
           Log.debug("XMPP: Unable to delete roster item from group.");
         }
       }
     }
   }
   for (String group : newgroups) {
     RosterGroup newgroup = conn.getRoster().createGroup(group);
     try {
       newgroup.addEntry(user2Update);
     } catch (XMPPException e) {
       Log.debug("XMPP: Unable to add roster item to new group.");
     }
   }
 }