1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

added functionality for removing roster entries

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2102 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2003-09-24 18:07:02 +00:00 committed by gdombiak
parent 5d628f4d36
commit 5286cb3895

View file

@ -249,6 +249,27 @@ public class Roster {
connection.sendPacket(presencePacket); connection.sendPacket(presencePacket);
} }
/**
* Removes a roster entry from the roster.
*
* @param entry a roster entry.
*/
public void removeEntry(RosterEntry entry) {
// Only remove the entry if it's in the entry list.
// The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
synchronized (entries) {
if (entries.contains(entry)) {
RosterPacket packet = new RosterPacket();
packet.setType(IQ.Type.SET);
RosterPacket.Item item = RosterEntry.toRosterItem(entry);
// Set the item type as REMOVE so that the server will delete the entry
item.setItemType(RosterPacket.ItemType.REMOVE);
packet.addRosterItem(item);
connection.sendPacket(packet);
}
}
}
/** /**
* Returns a count of the entries in the roster. * Returns a count of the entries in the roster.
* *
@ -509,54 +530,75 @@ public class Roster {
RosterEntry entry = new RosterEntry(item.getUser(), item.getName(), RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
item.getItemType(), connection); item.getItemType(), connection);
// Make sure the entry is in the entry list. // If the packet is of the type REMOVE then remove the entry
if (!entries.contains(entry)) { if (RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
entries.add(entry); // Remove the entry from the entry list.
} if (entries.contains(entry)) {
// If the roster entry belongs to any groups, remove it from the entries.remove(entry);
// list of unfiled entries.
if (item.getGroupNames().hasNext()) {
synchronized (unfiledEntries) {
unfiledEntries.remove(entry);
} }
} // Remove the entry from the unfiled entry list.
// Otherwise add it to the list of unfiled entries.
else {
synchronized (unfiledEntries) { synchronized (unfiledEntries) {
if (!unfiledEntries.contains(entry)) { if (unfiledEntries.contains(entry)) {
unfiledEntries.add(entry); unfiledEntries.remove(entry);
} }
} }
} }
else {
// Make sure the entry is in the entry list.
if (!entries.contains(entry)) {
entries.add(entry);
}
// If the roster entry belongs to any groups, remove it from the
// list of unfiled entries.
if (item.getGroupNames().hasNext()) {
synchronized (unfiledEntries) {
unfiledEntries.remove(entry);
}
}
// Otherwise add it to the list of unfiled entries.
else {
synchronized (unfiledEntries) {
if (!unfiledEntries.contains(entry)) {
unfiledEntries.add(entry);
}
}
}
}
// Find the list of groups that the user currently belongs to. // Find the list of groups that the user currently belongs to.
List currentGroupNames = new ArrayList(); List currentGroupNames = new ArrayList();
for (Iterator j = entry.getGroups(); j.hasNext(); ) { for (Iterator j = entry.getGroups(); j.hasNext(); ) {
RosterGroup group = (RosterGroup)j.next(); RosterGroup group = (RosterGroup)j.next();
currentGroupNames.add(group.getName()); currentGroupNames.add(group.getName());
} }
// Create the new list of groups the user belongs to.
List newGroupNames = new ArrayList(); // If the packet is not of the type REMOVE then add the entry to the groups
for (Iterator k = item.getGroupNames(); k.hasNext(); ) { if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
String groupName = (String)k.next(); // Create the new list of groups the user belongs to.
// Add the group name to the list. List newGroupNames = new ArrayList();
newGroupNames.add(groupName); for (Iterator k = item.getGroupNames(); k.hasNext(); ) {
String groupName = (String)k.next();
// Add the entry to the group. // Add the group name to the list.
RosterGroup group = getGroup(groupName); newGroupNames.add(groupName);
if (group == null) {
group = createGroup(groupName); // Add the entry to the group.
groups.put(groupName, group); RosterGroup group = getGroup(groupName);
if (group == null) {
group = createGroup(groupName);
groups.put(groupName, group);
}
// Add the entry.
group.addEntryLocal(entry);
}
// We have the list of old and new group names. We now need to
// remove the entry from the all the groups it may no longer belong
// to. We do this by subracting the new group set from the old.
for (int m=0; m<newGroupNames.size(); m++) {
currentGroupNames.remove(newGroupNames.get(m));
} }
// Add the entry.
group.addEntryLocal(entry);
} }
// We have the list of old and new group names. We now need to
// remove the entry from the all the groups it may no longer belong
// to. We do this by subracting the new group set from the old.
for (int m=0; m<newGroupNames.size(); m++) {
currentGroupNames.remove(newGroupNames.get(m));
}
// Loop through any groups that remain and remove the entries. // Loop through any groups that remain and remove the entries.
for (int n=0; n<currentGroupNames.size(); n++) { for (int n=0; n<currentGroupNames.size(); n++) {
String groupName = (String)currentGroupNames.get(n); String groupName = (String)currentGroupNames.get(n);