Updates display names when changed at server-side.

Auto accept authorizations if we have initiated adding of a contact.
cusax-fix
Damian Minkov 14 years ago
parent b003f7ffd6
commit 11526b8670

@ -379,6 +379,7 @@ service.gui.RENAME_CONTACT=Re&name contact
service.gui.RENAME_CONTACT_WIZARD=In the field below you can specify the name you would like to use for the given contact.
service.gui.RENAME_GROUP=Re&name group
service.gui.RENAME_GROUP_INFO=In the field below you can specify the name you would like to use for the given group.
service.gui.RENAME_CLEAR_USER_DEFINED=Clear User Defined
service.gui.RINGING_STATUS=Ringing
service.gui.REQUEST=&Request
service.gui.REQUEST_AUTHORIZATION=&Request authorization

@ -172,6 +172,13 @@ public class MclStorageManager
private static final String META_CONTACT_DISPLAY_NAME_NODE_NAME =
"display-name";
/**
* The name of the XML attribute that contains true/false, whether
* this meta contact was renamed by user.
*/
private static final String USER_DEFINED_DISPLAY_NAME_ATTR_NAME =
"user-defined";
/**
* The name of the XML node that contains meta contact detail.
*/
@ -777,6 +784,10 @@ private void processGroupXmlNode(MetaContactListServiceImpl mclServImpl,
String displayName = XMLUtils.getText(displayNameNode);
boolean isDisplayNameUserDefined =
Boolean.valueOf(displayNameNode
.getAttribute(USER_DEFINED_DISPLAY_NAME_ATTR_NAME));
// extract a map of all encapsulated proto contacts
List<MclStorageManager.StoredProtoContactDescriptor> protoContacts =
extractProtoContacts((Element) currentMetaContactNode,
@ -825,8 +836,12 @@ private void processGroupXmlNode(MetaContactListServiceImpl mclServImpl,
}
// pass the parsed proto contacts to the mcl service
mclServImpl.loadStoredMetaContact(currentMetaGroup, uid,
MetaContactImpl mc = mclServImpl.loadStoredMetaContact(
currentMetaGroup, uid,
displayName, details, protoContacts, accountID);
if(isDisplayNameUserDefined)
mc.setDisplayNameUserDefined(true);
}
catch (Throwable thr)
{
@ -1116,6 +1131,10 @@ private Element createMetaContactNode(MetaContact metaContact)
displayNameNode.appendChild(contactListDocument
.createTextNode(metaContact.getDisplayName()));
if(((MetaContactImpl)metaContact).isDisplayNameUserDefined())
displayNameNode.setAttribute(USER_DEFINED_DISPLAY_NAME_ATTR_NAME,
Boolean.TRUE.toString());
metaContactElement.appendChild(displayNameNode);
Iterator<Contact> contacts = metaContact.getContacts();
@ -1510,6 +1529,18 @@ public void metaContactRenamed(MetaContactRenamedEvent evt)
XMLUtils.findChild(metaContactNode,
META_CONTACT_DISPLAY_NAME_NODE_NAME);
if(((MetaContactImpl)evt.getSourceMetaContact())
.isDisplayNameUserDefined())
{
displayNameNode.setAttribute(USER_DEFINED_DISPLAY_NAME_ATTR_NAME,
Boolean.TRUE.toString());
}
else
{
displayNameNode.removeAttribute(
USER_DEFINED_DISPLAY_NAME_ATTR_NAME);
}
XMLUtils.setText(displayNameNode, evt.getNewDisplayName());
updatePersistentDataForMetaContact(evt.getSourceMetaContact());

@ -97,6 +97,11 @@ public class MetaContactImpl
*/
private final static String AVATAR_DIR = "avatarcache";
/**
* Whether user has renamed this meta contact.
*/
private boolean isDisplayNameUserDefined = false;
/**
* Characters and their replacement in created folder names
*/
@ -546,6 +551,26 @@ public String getDisplayName()
return displayName;
}
/**
* Determines if display name was changed for
* this <tt>MetaContact</tt> in user interface.
* @return whether display name was changed by user.
*/
boolean isDisplayNameUserDefined()
{
return isDisplayNameUserDefined;
}
/**
* Changes that display name was changed for
* this <tt>MetaContact</tt> in user interface.
* @param value control whether display name is user defined
*/
void setDisplayNameUserDefined(boolean value)
{
this.isDisplayNameUserDefined = value;
}
/**
* Queries a specific protocol <tt>Contact</tt> for its avatar. Beware that
* this method could cause multiple network operations. Use with caution.

@ -823,6 +823,23 @@ public MetaContactGroup getRoot()
*/
public void renameMetaContact(MetaContact metaContact, String newDisplayName)
throws IllegalArgumentException
{
renameMetaContact(metaContact, newDisplayName, true);
}
/**
* Sets the display name for <tt>metaContact</tt> to be <tt>newName</tt>.
* <p>
* @param metaContact the <tt>MetaContact</tt> that we are renaming
* @param newDisplayName a <tt>String</tt> containing the new display name
* for <tt>metaContact</tt>.
* @throws IllegalArgumentException if <tt>metaContact</tt> is not an
* instance that belongs to the underlying implementation.
*/
private void renameMetaContact(MetaContact metaContact,
String newDisplayName,
boolean isUserDefined)
throws IllegalArgumentException
{
if (! (metaContact instanceof MetaContactImpl))
{
@ -833,6 +850,8 @@ public void renameMetaContact(MetaContact metaContact, String newDisplayName)
String oldDisplayName = metaContact.getDisplayName();
((MetaContactImpl)metaContact).setDisplayName(newDisplayName);
if(isUserDefined)
((MetaContactImpl)metaContact).setDisplayNameUserDefined(true);
Iterator<Contact> contacts = metaContact.getContacts();
@ -873,6 +892,40 @@ public void renameMetaContact(MetaContact metaContact, String newDisplayName)
, MetaContactGroupEvent.CHILD_CONTACTS_REORDERED);
}
/**
* Resets display name of the MetaContact to show the value from
* the underlying contacts.
* @param metaContact the <tt>MetaContact</tt> that we are operating on
* @throws IllegalArgumentException if <tt>metaContact</tt> is not an
* instance that belongs to the underlying implementation.
*/
public void clearUserDefinedDisplayName(MetaContact metaContact)
throws IllegalArgumentException
{
if (! (metaContact instanceof MetaContactImpl))
{
throw new IllegalArgumentException(
metaContact + " is not a MetaContactImpl instance.");
}
// set display name
((MetaContactImpl)metaContact).setDisplayNameUserDefined(false);
if(metaContact.getContactCount() == 1)
{
renameMetaContact(metaContact,
metaContact.getDefaultContact().getDisplayName(), false);
}
else
{
// just fire event so the modification is stored
fireMetaContactEvent(new MetaContactRenamedEvent(
metaContact,
metaContact.getDisplayName(),
metaContact.getDisplayName()));
}
}
/**
* Sets the avatar for <tt>metaContact</tt> to be <tt>newAvatar</tt>.
* <p>
@ -2358,6 +2411,35 @@ public void subscriptionResolved(SubscriptionEvent evt)
if(mc != null)
{
mc.getAvatar();
if(mc.getContactCount() == 1
&& !mc.isDisplayNameUserDefined())
{
String oldDisplayName = mc.getDisplayName();
// if we have one contact, display name of metacontact
// haven't been changed by user
// and contact display name is different from
// metacontact's one let's change it
Contact c = mc.getDefaultContact();
String newDisplayName = c.getDisplayName();
if(newDisplayName != null
&& !newDisplayName.equals(oldDisplayName))
{
mc.setDisplayName(newDisplayName);
fireMetaContactEvent(new MetaContactRenamedEvent(
mc, oldDisplayName, newDisplayName));
//changing the display name has surely brought a change in the order as
//well so let's tell the others
fireMetaContactGroupEvent(
findParentMetaContactGroup( mc )
, null
, null
, MetaContactGroupEvent.CHILD_CONTACTS_REORDERED);
}
}
}
}
@ -2385,7 +2467,7 @@ public void contactModified(ContactPropertyChangeEvent evt)
if( evt.getOldValue() != null
&& evt.getOldValue().equals(mc.getDisplayName()))
{
renameMetaContact(mc, (String)evt.getNewValue());
renameMetaContact(mc, (String)evt.getNewValue(), false);
}
else
{
@ -2925,8 +3007,9 @@ ContactGroup loadStoredContactGroup(MetaContactGroupImpl containingMetaGroup,
* encapsulated by the meta contact that we're about to create.
* @param accountID the identifier of the account that the contacts
* originate from.
* @return the loaded meta contact.
*/
void loadStoredMetaContact(
MetaContactImpl loadStoredMetaContact(
MetaContactGroupImpl parentGroup,
String metaUID,
String displayName,
@ -2999,6 +3082,8 @@ void loadStoredMetaContact(
if (logger.isTraceEnabled())
logger.trace("Created meta contact: " + newMetaContact);
return newMetaContact;
}
/**

@ -35,6 +35,10 @@ public class RenameContactDialog
private JButton cancelButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.CANCEL"));
private JButton clearButton = new JButton(
GuiActivator.getResources().getI18NString(
"service.gui.RENAME_CLEAR_USER_DEFINED"));
private TransparentPanel buttonsPanel
= new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
@ -79,6 +83,7 @@ private void init()
this.getRootPane().setDefaultButton(renameButton);
this.renameButton.setName("rename");
this.cancelButton.setName("cancel");
this.clearButton.setName("clear");
this.renameButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.RENAME"));
@ -87,14 +92,27 @@ private void init()
this.renameButton.addActionListener(this);
this.cancelButton.addActionListener(this);
this.clearButton.addActionListener(this);
this.buttonsPanel.add(renameButton);
this.buttonsPanel.add(cancelButton);
TransparentPanel allButtonsPanel
= new TransparentPanel(new BorderLayout());
TransparentPanel firstButonPanel =
new TransparentPanel(new FlowLayout(FlowLayout.LEFT));
firstButonPanel.add(clearButton);
// add it only if we have one MetaContact
if(metaContact.getContactCount() == 1)
allButtonsPanel.add(firstButonPanel, BorderLayout.WEST);
allButtonsPanel.add(buttonsPanel, BorderLayout.CENTER);
this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
this.mainPanel.add(renameContactPanel, BorderLayout.NORTH);
this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
this.mainPanel.add(allButtonsPanel, BorderLayout.SOUTH);
this.getContentPane().add(mainPanel);
}
@ -123,6 +141,10 @@ public void run()
}.start();
}
}
else if (name.equals("clear"))
{
clist.clearDisplayNameUserDefined(metaContact);
}
this.dispose();
}

@ -63,6 +63,11 @@ public class ContactJabberImpl
*/
private String statusMessage = null;
/**
* The display name of the roster entry.
*/
private String serverDisplayName = null;
/**
* Creates an JabberContactImpl
* @param rosterEntry the RosterEntry object that we will be encapsulating.
@ -79,7 +84,10 @@ public class ContactJabberImpl
{
// rosterEntry can be null when creating volatile contact
if(rosterEntry != null)
{
this.jid = rosterEntry.getUser();
this.serverDisplayName = rosterEntry.getName();
}
this.tempId = null;
this.ssclCallback = ssclCallback;
@ -298,6 +306,25 @@ public String getDisplayName()
return getAddress();
}
/**
* Returns the display name used when the contact was resolved.
* Used to detect renames.
* @return the display name.
*/
String getServerDisplayName()
{
return serverDisplayName;
}
/**
* Changes locally stored server display name.
* @param newValue
*/
void setServerDisplayName(String newValue)
{
this.serverDisplayName = newValue;
}
/**
* Returns a reference to the contact group that this contact is currently
* a child of or null if the underlying protocol does not support persistent
@ -361,6 +388,7 @@ void setResolved(RosterEntry entry)
this.isResolved = true;
this.isPersistent = true;
this.jid = entry.getUser();
this.serverDisplayName = entry.getName();
}
/**

@ -1163,29 +1163,45 @@ public void run()
ContactJabberImpl srcContact
= ssContactList.findContactById(fromID);
if(srcContact == null)
srcContact = createVolatileContact(fromID);
AuthorizationRequest req = new AuthorizationRequest();
AuthorizationResponse response
= handler.processAuthorisationRequest(req, srcContact);
Presence.Type responsePresenceType = null;
if(response != null)
if(srcContact == null)
{
if(response.getResponseCode()
.equals(AuthorizationResponse.ACCEPT))
{
srcContact = createVolatileContact(fromID);
}
else
{
if(srcContact.isPersistent())
responsePresenceType = Presence.Type.subscribed;
if (logger.isInfoEnabled())
logger.info("Sending Accepted Subscription");
}
else if(response.getResponseCode()
.equals(AuthorizationResponse.REJECT))
}
if(responsePresenceType == null)
{
AuthorizationRequest req = new AuthorizationRequest();
AuthorizationResponse response
= handler.processAuthorisationRequest(
req, srcContact);
if(response != null)
{
responsePresenceType = Presence.Type.unsubscribed;
if (logger.isInfoEnabled())
logger.info("Sending Rejected Subscription");
if(response.getResponseCode()
.equals(AuthorizationResponse.ACCEPT))
{
responsePresenceType
= Presence.Type.subscribed;
if (logger.isInfoEnabled())
logger.info(
"Sending Accepted Subscription");
}
else if(response.getResponseCode()
.equals(AuthorizationResponse.REJECT))
{
responsePresenceType
= Presence.Type.unsubscribed;
if (logger.isInfoEnabled())
logger.info(
"Sending Rejected Subscription");
}
}
}

@ -1220,6 +1220,12 @@ public void entriesUpdated(Collection<String> addresses)
ContactJabberImpl contact = addEntryToContactList(contactID);
if(entry.getGroups().size() == 0)
{
// check for change in display name
checkForRename(entry.getName(), contact);
}
for (RosterGroup gr : entry.getGroups())
{
if(findContactGroup(gr.getName()) == null)
@ -1250,7 +1256,7 @@ public void entriesUpdated(Collection<String> addresses)
if(!gr.getName().equals(contactGroup.getGroupName()))
{
// the contact is moved to onether group
// the contact is moved to another group
// first remove it from the original one
if(contactGroup instanceof ContactGroupJabberImpl)
((ContactGroupJabberImpl)contactGroup).
@ -1269,11 +1275,38 @@ else if(contactGroup instanceof RootContactGroupJabberImpl)
newParentGroup,
contact);
}
else
{
// check for change in display name
checkForRename(entry.getName(), contact);
}
}
}
}
}
/**
* Checks the entry and the contact whether the display name has changed.
* @param newValue new display name value
* @param contact the contact to check
*/
private void checkForRename(String newValue,
ContactJabberImpl contact)
{
// check for change in display name
if(newValue != null
&& !newValue.equals(
contact.getServerDisplayName()))
{
String oldValue = contact.getServerDisplayName();
contact.setServerDisplayName(newValue);
parentOperationSet.fireContactPropertyChangeEvent(
ContactPropertyChangeEvent.PROPERTY_DISPLAY_NAME,
contact, oldValue, newValue);
}
}
/**
* Event received when entry has been removed from the list
* @param addresses Collection

@ -309,6 +309,16 @@ public void moveMetaContact(MetaContact metaContact,
public void renameMetaContact(MetaContact metaContact, String newName)
throws IllegalArgumentException;
/**
* Resets display name of the MetaContact to show the value from
* the underlying contacts.
* @param metaContact the <tt>MetaContact</tt> that we are operating on
* @throws IllegalArgumentException if <tt>metaContact</tt> is not an
* instance that belongs to the underlying implementation.
*/
public void clearUserDefinedDisplayName(MetaContact metaContact)
throws IllegalArgumentException;
/**
* Removes the specified <tt>metaContact</tt> as well as all of its
* underlying contacts.

Loading…
Cancel
Save