mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +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:
parent
5d628f4d36
commit
5286cb3895
1 changed files with 76 additions and 34 deletions
|
@ -249,6 +249,27 @@ public class Roster {
|
|||
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.
|
||||
*
|
||||
|
@ -509,6 +530,20 @@ public class Roster {
|
|||
RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
|
||||
item.getItemType(), connection);
|
||||
|
||||
// If the packet is of the type REMOVE then remove the entry
|
||||
if (RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
|
||||
// Remove the entry from the entry list.
|
||||
if (entries.contains(entry)) {
|
||||
entries.remove(entry);
|
||||
}
|
||||
// Remove the entry from the unfiled entry list.
|
||||
synchronized (unfiledEntries) {
|
||||
if (unfiledEntries.contains(entry)) {
|
||||
unfiledEntries.remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Make sure the entry is in the entry list.
|
||||
if (!entries.contains(entry)) {
|
||||
entries.add(entry);
|
||||
|
@ -528,12 +563,17 @@ public class Roster {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the list of groups that the user currently belongs to.
|
||||
List currentGroupNames = new ArrayList();
|
||||
for (Iterator j = entry.getGroups(); j.hasNext(); ) {
|
||||
RosterGroup group = (RosterGroup)j.next();
|
||||
currentGroupNames.add(group.getName());
|
||||
}
|
||||
|
||||
// If the packet is not of the type REMOVE then add the entry to the groups
|
||||
if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
|
||||
// Create the new list of groups the user belongs to.
|
||||
List newGroupNames = new ArrayList();
|
||||
for (Iterator k = item.getGroupNames(); k.hasNext(); ) {
|
||||
|
@ -557,6 +597,8 @@ public class Roster {
|
|||
for (int m=0; m<newGroupNames.size(); m++) {
|
||||
currentGroupNames.remove(newGroupNames.get(m));
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through any groups that remain and remove the entries.
|
||||
for (int n=0; n<currentGroupNames.size(); n++) {
|
||||
String groupName = (String)currentGroupNames.get(n);
|
||||
|
|
Loading…
Reference in a new issue