diff options
author | Damian Minkov <damencho@jitsi.org> | 2013-09-26 16:30:19 +0300 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2013-09-26 16:30:19 +0300 |
commit | cdc0a4229a9b1a94f554bdeb28f8c6dfbb1df5d1 (patch) | |
tree | 1e1ed2d932c7d55bba4f27bfd3074b51ae43f305 | |
parent | 997f26507928acce57110bdab589a40f762256e8 (diff) | |
download | jitsi-cdc0a4229a9b1a94f554bdeb28f8c6dfbb1df5d1.zip jitsi-cdc0a4229a9b1a94f554bdeb28f8c6dfbb1df5d1.tar.gz jitsi-cdc0a4229a9b1a94f554bdeb28f8c6dfbb1df5d1.tar.bz2 |
Fixes discovering cusax connected contacts when using call history.
7 files changed, 296 insertions, 71 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index 193c1e4..d8144d8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -1323,8 +1323,21 @@ public class CallManager UIContactImpl uiContact = CallManager.getCallUIContact(peer.getCall()); - if (uiContact != null) - displayName = uiContact.getDisplayName(); + if(uiContact != null) + { + if(uiContact.getDescriptor() instanceof SourceContact) + { + // if it is source contact (history record) + // search for cusax contact match + Contact contact = getPeerCusaxContact(peer.getAddress(), + (SourceContact)uiContact.getDescriptor()); + if(contact != null) + displayName = contact.getDisplayName(); + } + + if(StringUtils.isNullOrEmpty(displayName, true)) + displayName = uiContact.getDisplayName(); + } // We search for a contact corresponding to this call peer and // try to get its display name. @@ -1413,12 +1426,22 @@ public class CallManager UIContactImpl uiContact = CallManager.getCallUIContact(peer.getCall()); - if (uiContact != null - && !(uiContact.getDescriptor() instanceof SourceContact - && ((SourceContact)uiContact.getDescriptor()) - .isDefaultImage())) + if (uiContact != null) { - image = uiContact.getAvatar(); + if(uiContact.getDescriptor() instanceof SourceContact + && ((SourceContact)uiContact.getDescriptor()) + .isDefaultImage()) + { + // if it is source contact (history record) + // search for cusax contact match + Contact contact = getPeerCusaxContact(peer.getAddress(), + (SourceContact)uiContact.getDescriptor()); + + if(contact != null) + image = contact.getImage(); + } + else + image = uiContact.getAvatar(); } } @@ -1498,6 +1521,17 @@ public class CallManager return contact; } } + else if(uiContact.getDescriptor() instanceof SourceContact) + { + // if it is source contact (history record) + // search for cusax contact match + Contact contact = getPeerCusaxContact(peer.getAddress(), + (SourceContact)uiContact.getDescriptor()); + if(contact != null + && contact.getProtocolProvider().getOperationSet( + OperationSetBasicInstantMessaging.class) != null) + return contact; + } } // We try to find the an alternative peer address. @@ -1538,6 +1572,110 @@ public class CallManager } /** + * Find is there a linked cusax protocol provider for this source contact, + * if it exist we try to resolve current peer to one of its contacts + * or details of a contact (numbers). + * @param peerAddress the address of the peer to check + * @param sourceContact the currently selected source contact. + * @return matching cusax contact. + */ + private static Contact getPeerCusaxContact( + String peerAddress, SourceContact sourceContact) + { + ProtocolProviderService linkedCusaxProvider = null; + for(ContactDetail detail : sourceContact.getContactDetails()) + { + ProtocolProviderService pps + = detail.getPreferredProtocolProvider( + OperationSetBasicTelephony.class); + + if(pps != null) + { + OperationSetCusaxUtils cusaxOpSet = + pps.getOperationSet(OperationSetCusaxUtils.class); + + if(cusaxOpSet != null) + { + linkedCusaxProvider + = cusaxOpSet.getLinkedCusaxProvider(); + break; + } + } + } + + if(linkedCusaxProvider != null) + { + OperationSetPersistentPresence opSetPersistentPresence + = linkedCusaxProvider.getOperationSet( + OperationSetPersistentPresence.class); + + if(opSetPersistentPresence != null) + { + // will strip the @server-address part, as the regular expression + // will match it + int index = peerAddress.indexOf("@"); + String peerUserID = + (index > -1) ? peerAddress.substring(0, index) : peerAddress; + + // searches for the whole number/username or with the @serverpart + String peerUserIDQ = Pattern.quote(peerUserID); + + Pattern pattern = Pattern.compile( + "^(" + peerUserIDQ + "|" + peerUserIDQ + "@.*)$"); + + return findContactByPeer( + peerUserID, + pattern, + opSetPersistentPresence.getServerStoredContactListRoot(), + linkedCusaxProvider.getOperationSet( + OperationSetCusaxUtils.class)); + } + } + + return null; + } + + /** + * Finds a matching cusax contact. + * @param peerUserID the userID of the call peer to search for + * @param searchPattern the pattern (userID | userID@...) + * @param parent the parent group of the groups and contacts to search in + * @param cusaxOpSet the opset of the provider which will be used to match + * contact's details to peer userID (stored numbers). + * @return a cusax matching contac + */ + private static Contact findContactByPeer( + String peerUserID, + Pattern searchPattern, + ContactGroup parent, + OperationSetCusaxUtils cusaxOpSet) + { + Iterator<Contact> contactIterator = parent.contacts(); + while(contactIterator.hasNext()) + { + Contact contact = contactIterator.next(); + + if(searchPattern.matcher(contact.getAddress()).find() + || cusaxOpSet.doesDetailBelong(contact, peerUserID)) + { + return contact; + } + } + + Iterator<ContactGroup> groupsIterator = parent.subgroups(); + while(groupsIterator.hasNext()) + { + ContactGroup gr = groupsIterator.next(); + Contact contact = findContactByPeer( + peerUserID, searchPattern, gr, cusaxOpSet); + if(contact != null) + return contact; + } + + return null; + } + + /** * Returns the image for the given contact. * * @param contact the <tt>Contact</tt>, which image we're looking for @@ -1623,6 +1761,15 @@ public class CallManager { return (MetaContact)uiContact.getDescriptor(); } + else if(uiContact.getDescriptor() instanceof SourceContact) + { + // if it is a source contact check for matching cusax contact + Contact contact = getPeerCusaxContact(peer.getAddress(), + (SourceContact)uiContact.getDescriptor()); + if(contact != null) + return GuiActivator.getContactListService() + .findMetaContactByContact(contact); + } } String imppAddress = peer.getAlternativeIMPPAddress(); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetCusaxUtilsJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetCusaxUtilsJabberImpl.java index 58d973e..65a3472 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetCusaxUtilsJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetCusaxUtilsJabberImpl.java @@ -70,4 +70,15 @@ public class OperationSetCusaxUtilsJabberImpl return false; } + + /** + * Returns the linked CUSAX provider for this protocol provider. + * + * @return the linked CUSAX provider for this protocol provider or null + * if such isn't specified + */ + public ProtocolProviderService getLinkedCusaxProvider() + { + return null; + } }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetCusaxUtilsSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetCusaxUtilsSipImpl.java new file mode 100644 index 0000000..8a5e204 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetCusaxUtilsSipImpl.java @@ -0,0 +1,95 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; + +/** + * The <tt>OperationSetCusaxUtilsSipImpl</tt> provides utility methods + * related to the SIP CUSAX implementation. + * + * @author Damian Minkov + */ +public class OperationSetCusaxUtilsSipImpl + implements OperationSetCusaxUtils +{ + /** + * Our class logger. + */ + private static final Logger logger = + Logger.getLogger(OperationSetCusaxUtilsSipImpl.class); + + /** + * The parent jabber protocol provider. + */ + private final ProtocolProviderServiceSipImpl provider; + + /** + * Constructs this operation set. + * @param provider the parent provider. + */ + public OperationSetCusaxUtilsSipImpl( + ProtocolProviderServiceSipImpl provider) + { + this.provider = provider; + } + + /** + * Checks if the given <tt>detailAddress</tt> exists in the given + * <tt>contact</tt> details. + * + * @param contact the <tt>Contact</tt>, which details to check + * @param detailAddress the detail address we're looking for + * @return <tt>true</tt> if the given <tt>detailAdress</tt> exists in the + * details of the given <tt>contact</tt> + */ + public boolean doesDetailBelong(Contact contact, String detailAddress) + { + return false; + } + + /** + * Returns the linked CUSAX provider for this protocol provider. + * + * @return the linked CUSAX provider for this protocol provider or null + * if such isn't specified + */ + public ProtocolProviderService getLinkedCusaxProvider() + { + String cusaxProviderID = provider.getAccountID() + .getAccountPropertyString( + ProtocolProviderFactory.CUSAX_PROVIDER_ACCOUNT_PROP); + + if (cusaxProviderID == null) + return null; + + AccountID acc + = ProtocolProviderActivator.getAccountManager() + .findAccountID(cusaxProviderID); + + if(acc == null) + { + logger.warn("No connected cusax account found for " + + cusaxProviderID); + return null; + } + else + { + for (ProtocolProviderService pProvider : + ProtocolProviderActivator.getProtocolProviders()) + { + if(pProvider.getAccountID().equals(acc)) + { + return pProvider; + } + } + } + + return null; + } +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java index cc7017e..0d23dfc 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -566,6 +566,14 @@ public class ProtocolProviderServiceSipImpl new OperationSetMessageWaitingSipImpl(this)); } + if(getAccountID().getAccountPropertyString( + ProtocolProviderFactory.CUSAX_PROVIDER_ACCOUNT_PROP) != null) + { + addSupportedOperationSet( + OperationSetCusaxUtils.class, + new OperationSetCusaxUtilsSipImpl(this)); + } + //initialize our OPTIONS handler new ClientCapabilities(this); @@ -2570,44 +2578,4 @@ public class ProtocolProviderServiceSipImpl || ListeningPoint.TLS.equalsIgnoreCase(transport) || ListeningPoint.TCP.equalsIgnoreCase(transport); } - - /** - * Returns the linked CUSAX provider for this SIP protocol provider. - * - * @return the linked CUSAX provider for this SIP protocol provider or null - * if such isn't specified - */ - public ProtocolProviderService getLinkedCusaxProvider() - { - String cusaxProviderID = getAccountID() - .getAccountPropertyString( - ProtocolProviderFactory.CUSAX_PROVIDER_ACCOUNT_PROP); - - if (cusaxProviderID == null) - return null; - - AccountID acc - = ProtocolProviderActivator.getAccountManager() - .findAccountID(cusaxProviderID); - - if(acc == null) - { - logger.warn("No connected cusax account found for " - + cusaxProviderID); - return null; - } - else - { - for (ProtocolProviderService pProvider : - ProtocolProviderActivator.getProtocolProviders()) - { - if(pProvider.getAccountID().equals(acc)) - { - return pProvider; - } - } - } - - return null; - } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipMessageFactory.java b/src/net/java/sip/communicator/impl/protocol/sip/SipMessageFactory.java index 3c3fd18..9d7f840 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipMessageFactory.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipMessageFactory.java @@ -798,8 +798,13 @@ public class SipMessageFactory CallInfoHeader callInfoHeader = null; try { - ProtocolProviderService cusaxProvider - = protocolProvider.getLinkedCusaxProvider(); + ProtocolProviderService cusaxProvider = null; + + OperationSetCusaxUtils cusaxOpSet = + protocolProvider.getOperationSet(OperationSetCusaxUtils.class); + + if(cusaxOpSet != null) + cusaxProvider = cusaxOpSet.getLinkedCusaxProvider(); String alternativeImppAddress = null; diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetCusaxUtils.java b/src/net/java/sip/communicator/service/protocol/OperationSetCusaxUtils.java index 1bcdfc9..871dd89 100644 --- a/src/net/java/sip/communicator/service/protocol/OperationSetCusaxUtils.java +++ b/src/net/java/sip/communicator/service/protocol/OperationSetCusaxUtils.java @@ -25,4 +25,12 @@ public interface OperationSetCusaxUtils * details of the given <tt>contact</tt> */ public boolean doesDetailBelong(Contact contact, String detailAddress); + + /** + * Returns the linked CUSAX provider for this protocol provider. + * + * @return the linked CUSAX provider for this protocol provider or null + * if such isn't specified + */ + public ProtocolProviderService getLinkedCusaxProvider(); } diff --git a/src/net/java/sip/communicator/service/protocol/SingleCallInProgressPolicy.java b/src/net/java/sip/communicator/service/protocol/SingleCallInProgressPolicy.java index f4da362..bf96d80 100644 --- a/src/net/java/sip/communicator/service/protocol/SingleCallInProgressPolicy.java +++ b/src/net/java/sip/communicator/service/protocol/SingleCallInProgressPolicy.java @@ -386,31 +386,22 @@ public class SingleCallInProgressPolicy { // there is no presence opset let's check // the connected cusax provider if available - String cusaxProviderID = provider.getAccountID() - .getAccountPropertyString( - ProtocolProviderFactory.CUSAX_PROVIDER_ACCOUNT_PROP); - - AccountID acc = - ProtocolProviderActivator.getAccountManager() - .findAccountID(cusaxProviderID); - if(acc == null) - { - logger.warn("No connected cusax account found for " - + cusaxProviderID); - } - else + OperationSetCusaxUtils cusaxOpSet = + provider.getOperationSet(OperationSetCusaxUtils.class); + + if(cusaxOpSet != null) { - for(ProtocolProviderService pProvider : - ProtocolProviderActivator.getProtocolProviders()) + ProtocolProviderService linkedCusaxProvider + = cusaxOpSet.getLinkedCusaxProvider(); + + if(linkedCusaxProvider != null) { - if(pProvider.getAccountID().equals(acc)) - { - // we found the provider, lets take its - // presence opset - presence = pProvider.getOperationSet( - OperationSetPresence.class); - } + // we found the provider, lets take its + // presence opset + presence = linkedCusaxProvider.getOperationSet( + OperationSetPresence.class); } + } } |