patch to make moving contacts bewteen group working without loose of information & authorization:
/**
-
@param contact Screen name/UIN of the contact.
-
@param nickname Nickname of the contact (should not be null)
-
@param grouplist List of groups the contact should be a member of.
*/
public void syncContactGroupsAndNickname(String contact, String nickname, List();
}
if (grouplist.isEmpty()) {
if (getTransport().getType().equals(TransportType.icq)) {
grouplist.add(DEFAULT_ICQ_GROUP);
}
else {
grouplist.add(DEFAULT_AIM_GROUP);
}
}
// TODO: add another step here where we attempt to “move around” contacts instead of just adding and deleting
Log.debug("contact = “contact”, grouplist = "+grouplist);
OSCARBuddy oscarBuddy = null;
try {
oscarBuddy = (OSCARBuddy)getBuddyManager().getBuddy(getTransport().convertIDToJID(contact));
}
catch (NotFoundException e) {
}
Vector freeBuddyItems = new Vector();
if (oscarBuddy != null) {
// Now, lets clean up any groups this contact should no longer be a member of.
for (BuddyItem buddy : oscarBuddy.getBuddyItems()) {
if (buddy.getScreenname().equalsIgnoreCase(contact)) {
if (buddy.getGroupId() == 0 && !grouplist.contains(DEFAULT_AIM_GROUP)) {
// Ok this group is the “main group”, but contact isn’t in it.
Log.debug(“Removing “buddy” from main group”);
freeBuddyItems.add(b uddy);
}
else if (!groups.containsKey(buddy.getGroupId())) {
// Well this is odd, a group we don’t know about? Nuke it.
Log.debug(“Removing “buddy” because of unknown group”);
freeBuddyItems.add(b uddy);
}
else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
Log.debug(“Removing “buddy” because not in list of groups”);
freeBuddyItems.add(b uddy);
}
else {
if (buddy.getAlias() == null || !buddy.getAlias().equals(nickname)) {
Log.debug( "Updating alias for "+buddy);
buddy.setA lias(nickname);
request(ne w ModifyItemsCmd(buddy.toSsiItem()));
oscarBuddy .tieBuddyItem(buddy, true);
}
}
}
}
}
// First, lets take the known good list of groups and add whatever is missing on the server.
for (String group : grouplist) {
Integer groupId = getGroupIdOrCreateNew(group);
if (isMemberOfGroup(groupId, contact)) {
// Already a member, moving on
continue;
}
Integer newBuddyId = 1;
if (highestBuddyIdPerGroup.containsKey(groupId)) {
newBuddyId = highestBuddyIdPerGroup.get(groupId) + 1;
}
if (freeBuddyItems.size() > 0) { // moving a free buddy
BuddyItem buddy = (BuddyItem)freeBuddyItems.get(0);
BuddyItem newBuddy = new BuddyItem(contact, groupId, newBuddyId, nickname, buddy.getBuddyComment(), buddy.getAlertWhenMask(), buddy.getAlertActionMask(), buddy.getAlertSound(), false, buddy.getExtraTlvs());
request(new DeleteItemsCmd(buddy.toSsiItem()));
oscarBuddy.removeBuddyItem(buddy.getGrou pId(), false);
freeBuddyItems.remove(buddy);
oscarBuddy.tieBuddyItem(newBuddy, false);
request(new CreateItemsCmd(newBuddy.toSsiItem()));
} else { // creating a new buddy
BuddyItem newBuddy = new BuddyItem(contact, groupId, newBuddyId);
newBuddy.setAlias(nickname);
if (oscarBuddy == null) {
getBuddyManager().storeBuddy(o scarBuddy = new OSCARBuddy(getBuddyManager(), newBuddy));
} else {
oscarBuddy.tieBuddyItem(newBud dy, false);
}
request(new CreateItemsCmd(newBuddy.toSsiItem()));
// TODO: translate this
request(new BuddyAuthRequest(contact, “Automated add request on behalf of user.”));
}
}
for (int i=0; i<freeBuddyItems.size(); i++) {
BuddyItem buddy = (BuddyItem)freeBuddyItems.get(i);
request(new DeleteItemsCmd(buddy.toSsiItem()));
oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
}
}
/code