From d7d5801d63cbec94aad2784a5ace39a3c75edecd Mon Sep 17 00:00:00 2001 From: Vincent Lucas Date: Wed, 7 Aug 2013 18:46:55 +0200 Subject: [PATCH] Improves resolving ids for Outlook contacts. --- .../MsOutlookAddrBookContactQuery.java | 72 +++++++++++-------- .../MsOutlookAddrBookSourceContact.java | 30 +++++--- 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java index 944113fcb..a9a16769b 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java +++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java @@ -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; + } } } } diff --git a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookSourceContact.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookSourceContact.java index 0b4057633..3886e03a0 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookSourceContact.java +++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookSourceContact.java @@ -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; } /**