@Nullable private static String getUserGroup(RosterEntry rosterEntry) { String group = null; for (RosterGroup rosterGroup : rosterEntry.getGroups()) { group = rosterGroup.getName(); } return group; }
static RosterPacket.Item toRosterItem(RosterEntry entry) { RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName()); item.setItemType(entry.getType()); item.setItemStatus(entry.getStatus()); // Set the correct group names for the item. for (RosterGroup group : entry.getGroups()) { item.addGroupName(group.getName()); } return item; }
/** * Returns an unmodifiable collection of the roster groups that this entry belongs to. * * @return an iterator for the groups this entry belongs to. */ public Collection<RosterGroup> getGroups() { List<RosterGroup> results = new ArrayList<RosterGroup>(); // Loop through all roster groups and find the ones that contain this // entry. This algorithm should be fine for (RosterGroup group : roster.getGroups()) { if (group.contains(this)) { results.add(group); } } return Collections.unmodifiableCollection(results); }
public String toString() { StringBuilder buf = new StringBuilder(); if (name != null) { buf.append(name).append(": "); } buf.append(user); Collection<RosterGroup> groups = getGroups(); if (!groups.isEmpty()) { buf.append(" ["); Iterator<RosterGroup> iter = groups.iterator(); RosterGroup group = iter.next(); buf.append(group.getName()); while (iter.hasNext()) { buf.append(", "); group = iter.next(); buf.append(group.getName()); } buf.append("]"); } return buf.toString(); }
/** * Sends a roster group to userID. All the entries of the group will be sent to the target user. * * @param rosterGroup the roster group to send * @param targetUserID the user that will receive the roster entries */ public void send(RosterGroup rosterGroup, String targetUserID) { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message RosterExchange rosterExchange = new RosterExchange(); for (RosterEntry entry : rosterGroup.getEntries()) { rosterExchange.addRosterEntry(entry); } msg.addExtension(rosterExchange); // Send the message that contains the roster con.sendPacket(msg); }
/** * @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."); } } }
@Override public String getName() { return rosterGroup.getName(); }