Handles more cases while moving contacts and renaming groups from remote logged in locations.

cusax-fix
Damian Minkov 12 years ago
parent b4c97b9c90
commit e32b56e234

@ -2792,7 +2792,6 @@ public void groupResolved(ServerStoredGroupEvent evt)
*/
public void groupRemoved(ServerStoredGroupEvent evt)
{
if (logger.isTraceEnabled())
logger.trace("ContactGroup removed: " + evt);
@ -2810,10 +2809,10 @@ public void groupRemoved(ServerStoredGroupEvent evt)
removeContactGroupFromMetaContactGroup(metaContactGroup,
evt.getSourceGroup(), evt.getSourceProvider());
//do not remove the meta contact group even if this is the las
//protocol specific contact group. Contrary to contacts, meta
//contact groups are to only be remove upon user indication or
//otherwise it would be difficult for a user to create a new grp.
if(metaContactGroup.countContactGroups() == 0)
{
removeMetaContactGroup(metaContactGroup);
}
}
/**
@ -2830,6 +2829,14 @@ public void groupNameChanged(ServerStoredGroupEvent evt)
MetaContactGroup metaContactGroup
= findMetaContactGroupByContactGroup(evt.getSourceGroup());
if(metaContactGroup.countContactGroups() == 1)
{
// if the only group contained in this group is renamed
// rename it
((MetaContactGroupImpl)metaContactGroup)
.setGroupName(evt.getSourceGroup().getGroupName());
}
fireMetaContactGroupEvent(
metaContactGroup
, evt.getSourceProvider()

@ -341,7 +341,8 @@ private ContactGroupJabberImpl findContactGroupByNameCopy(String name)
ContactGroupJabberImpl contactGroup
= (ContactGroupJabberImpl) contactGroups.next();
if (contactGroup.getNameCopy().trim().equals(name))
if (contactGroup.getNameCopy() != null
&& contactGroup.getNameCopy().trim().equals(name))
return contactGroup;
}
@ -639,7 +640,7 @@ public void createGroup(String groupName)
ContactGroupJabberImpl newGroup =
new ContactGroupJabberImpl(newRosterGroup,
new Vector<RosterEntry>().iterator(),
new ArrayList<RosterEntry>().iterator(),
this,
true);
rootGroup.addSubGroup(newGroup);
@ -1364,7 +1365,8 @@ public void entriesUpdated(Collection<String> addresses)
for (RosterGroup gr : entry.getGroups())
{
if(findContactGroup(gr.getName()) == null)
ContactGroup cgr = findContactGroup(gr.getName());
if(cgr == null)
{
// such group does not exist. so it must be
// renamed one
@ -1380,10 +1382,53 @@ public void entriesUpdated(Collection<String> addresses)
}
else
{
// strange ???
// the group was renamed on different location
// so we do not have it at our side
// now lets find the group for the contact
// and rename it,
// - if it is the only contact in
// the group this is rename, otherwise it is move
ContactGroup currentParentGroup =
contact.getParentContactGroup();
if(currentParentGroup.countContacts() > 1)
{
cgr = currentParentGroup;
}
else
{
// make sure this group name is not present
// in entry groups
boolean present = false;
for (RosterGroup entryGr : entry.getGroups())
{
if(entryGr.getName().equals(
currentParentGroup.getGroupName()))
{
present = true;
break;
}
}
if(!present
&& currentParentGroup instanceof
ContactGroupJabberImpl)
{
ContactGroupJabberImpl currentGroup =
(ContactGroupJabberImpl)
currentParentGroup;
currentGroup.setSourceGroup(gr);
fireGroupEvent(
currentGroup,
ServerStoredGroupEvent
.GROUP_RENAMED_EVENT);
}
}
}
}
else
if(cgr != null)
{
// the group is found the contact may be moved from
// one group to another
@ -1405,16 +1450,45 @@ else if(contactGroup instanceof RootContactGroupJabberImpl)
ContactGroupJabberImpl newParentGroup =
findContactGroup(gr.getName());
// the new parent group maybe missing
if(newParentGroup == null)
{
// create the group as it doesn't exist
newParentGroup =
new ContactGroupJabberImpl(
gr,
new ArrayList<RosterEntry>().iterator(),
ServerStoredContactListJabberImpl.this,
true);
rootGroup.addSubGroup(newParentGroup);
//tell listeners about the added group
fireGroupEvent(newParentGroup,
ServerStoredGroupEvent.GROUP_CREATED_EVENT);
}
newParentGroup.addContact(contact);
fireContactMoved(contactGroup,
newParentGroup,
contact);
newParentGroup,
contact);
if(contactGroup instanceof ContactGroupJabberImpl
&& contactGroup.countContacts() == 0)
{
// in xmpp if group is empty it is removed
rootGroup.removeSubGroup(
(ContactGroupJabberImpl)contactGroup);
fireGroupEvent(
(ContactGroupJabberImpl)contactGroup,
ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
}
}
else
{
// check for change in display name
checkForRename(entry.getName(), contact);
}
}

@ -606,7 +606,7 @@ public void testGroupChangeEventHandling() throws Exception
evt = (MetaContactGroupEvent)mclEvtCollector
.collectedMetaContactGroupEvents.get(
mclEvtCollector
.collectedMetaContactGroupEvents.size() - 1);
.collectedMetaContactGroupEvents.size() - 2);
mclEvtCollector.collectedMetaContactGroupEvents.clear();
assertEquals("ID of the generated event",

Loading…
Cancel
Save