List<String> newGroups = new ArrayList<>(contact.getGroups());
newGroups.remove(contactGroup.getFullName());
newGroups.add(newName);
// Only do a roster update, if the groups have really changed.
if (!contact.getGroups().equals(newGroups)) {
updateContact(new Contact(contact.getJid(), contact.getName(), newGroups));
}
}
for (ContactGroup subGroup : contactGroup.getGroups()) {
replaceGroupName(subGroup, name, index);
}