Improves resolving ids for Outlook contacts.

cusax-fix 4783
Vincent Lucas 13 years ago
parent 625e21dd62
commit d7d5801d63

@ -1046,14 +1046,40 @@ protected void run()
*/
public void inserted(String id)
{
SourceContact sourceContact = findSourceContactByID(id);
insertedOrUpdated(id, 0);
}
/**
* Callback method when receiving notifications for updated items.
*
* @param id The outlook contact identifier.
*/
public void updated(String id)
{
insertedOrUpdated(id, 1);
}
/**
* Callback method when receiving notifications for updated items.
*
* @param id The outlook contact identifier.
* @param maxLevel The maximum level for comparing ids: 0 cached ids only, 1
* cached ids and outlook database ids.
*/
public void insertedOrUpdated(String id, int maxLevel)
{
SourceContact sourceContact = findSourceContactByID(id, maxLevel);
if(sourceContact != null
&& sourceContact instanceof MsOutlookAddrBookSourceContact)
{
updated(((MsOutlookAddrBookSourceContact) sourceContact).getId());
// updated
((MsOutlookAddrBookSourceContact) sourceContact).updated();
fireContactChanged(sourceContact);
}
else
{
// inserted
try
{
onMailUser(id);
@ -1071,26 +1097,6 @@ public void inserted(String id)
}
}
/**
* Callback method when receiving notifications for updated items.
*
* @param id The outlook contact identifier.
*/
public void updated(String id)
{
SourceContact sourceContact = findSourceContactByID(id);
if(sourceContact != null
&& sourceContact instanceof MsOutlookAddrBookSourceContact)
{
((MsOutlookAddrBookSourceContact) sourceContact).updated();
fireContactChanged(sourceContact);
}
else
{
inserted(id);
}
}
/**
* Callback method when receiving notifications for deleted items.
*
@ -1100,7 +1106,7 @@ public void deleted(String id)
{
if(id != null)
{
SourceContact sourceContact = findSourceContactByID(id);
SourceContact sourceContact = findSourceContactByID(id, 1);
if(sourceContact != null)
{
@ -1224,19 +1230,27 @@ public static String getOrganization(Object[] values)
/**
* Searches for source contact with the specified id.
* @param id the id to search for
*
* @param id the id to search for.
* @param maxLevel The maximum level for comparing ids: 0 cached ids only, 1
* cached ids and outlook database ids.
*
* @return the source contact found or null.
*/
protected SourceContact findSourceContactByID(String id)
protected SourceContact findSourceContactByID(String id, int maxLevel)
{
synchronized(sourceContacts)
{
for(SourceContact sc : sourceContacts)
for(int level = 0; level <= maxLevel; ++level)
{
if(sc instanceof MsOutlookAddrBookSourceContact
&& ((MsOutlookAddrBookSourceContact) sc).match(id))
for(SourceContact sc : sourceContacts)
{
return sc;
if(sc instanceof MsOutlookAddrBookSourceContact
&& ((MsOutlookAddrBookSourceContact) sc)
.match(id, level))
{
return sc;
}
}
}
}

@ -349,22 +349,32 @@ public int getIndex()
/**
* Tells if the id given in parameters corresponds to this contact.
*
* @param id The id to compare with.
* @param level 0 to only look at cached ids. 1 to only look at outlook
* database ids.
*
* @return True if the id given in parameters corresponds to this contact.
* False otherwise.
*/
public boolean match(String id)
public boolean match(String id, int level)
{
if(!this.ids.contains(id))
boolean res = false;
switch(level)
{
String localId = this.getId();
if(!MsOutlookAddrBookContactQuery.compareEntryIds(id, localId))
{
return false;
}
this.ids.add(id);
case 0:
res = this.ids.contains(id);
break;
case 1:
String localId = this.getId();
res =
MsOutlookAddrBookContactQuery.compareEntryIds(id, localId);
if(res && !this.ids.contains(id))
{
this.ids.add(id);
}
break;
}
return true;
return res;
}
/**

Loading…
Cancel
Save