Adds automatically the server part of a jabber contact during add.

cusax-fix
Yana Stamcheva 15 years ago
parent 6756b9e567
commit 3265ec17aa

@ -200,12 +200,19 @@ public int hashCode()
public boolean equals(Object obj)
{
if (obj == null
|| !(obj instanceof ContactJabberImpl)
|| !(((ContactJabberImpl)obj).getAddress()
|| !(obj instanceof String || (obj instanceof ContactJabberImpl)))
return false;
if (obj != null && obj instanceof ContactJabberImpl
&& !(((ContactJabberImpl)obj).getAddress()
.equalsIgnoreCase(getAddress())
&& ((ContactJabberImpl)obj).getProtocolProvider()
== getProtocolProvider()))
return false;
if (obj != null && obj instanceof String
&& !(getAddress().substring(0, getAddress().indexOf("@"))
.equals(obj)))
return false;
return true;

@ -426,19 +426,21 @@ public void addContact(ContactGroup parent, String id)
if (logger.isTraceEnabled())
logger.trace("Adding contact " + id + " to parent=" + parent);
String completeID = parseAddressString(id);
//if the contact is already in the contact list and is not volatile,
//then only broadcast an event
ContactJabberImpl existingContact = findContactById(id);
ContactJabberImpl existingContact = findContactById(completeID);
if( existingContact != null
&& existingContact.isPersistent() )
{
if(logger.isDebugEnabled())
logger.debug("Contact " + id
logger.debug("Contact " + completeID
+ " already exists in group "
+ findContactGroup(existingContact));
throw new OperationFailedException(
"Contact " + id + " already exists.",
"Contact " + completeID + " already exists.",
OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS);
}
@ -449,7 +451,7 @@ public void addContact(ContactGroup parent, String id)
if(parent != null)
parentNames = new String[]{parent.getGroupName()};
this.roster.createEntry(id, id, parentNames);
this.roster.createEntry(completeID, completeID, parentNames);
}
catch (XMPPException ex)
{
@ -1438,4 +1440,20 @@ private byte[] getAvatar(ContactJabberImpl contact)
}
}
}
/**
* Completes the identifier with the server part if no server part was
* previously added.
*
* @param id the initial identifier as added by the user
*/
private String parseAddressString(String id)
{
if (id.indexOf("@") < 0)
{
return id + "@" + jabberProvider.getAccountID().getService();
}
return id;
}
}

@ -519,7 +519,6 @@ public boolean equals(Object obj)
return this.getAddress().equals(sipContact.getAddress());
}
/**
* Returns the presence operation set that this contact belongs
* to.

Loading…
Cancel
Save