Showing posts with label Spark 2.5.8. Show all posts
Showing posts with label Spark 2.5.8. Show all posts

Friday, January 30, 2015

Spark2.5.8 JID Nick Name | Spark 2.5.8 - Use JID Instead of Nick Name in Chat UI

Customize Spark: Use JID instead Nick Name

By default, Spark uses nick name (e.g. admin) in its private/group chat windows. If you want to use JID (e.g. admin@server/Spark) instead, consider the following two ways:
1.
private String getJidFromPresencePacket(Presence p)
{
  Collection<PacketExtension> extensions = p.getExtensions();      
  
  if (extensions instanceof List && !extensions.isEmpty())
  {
    Object obj = ((List<?>)extensions).get(0);
    
    if (obj instanceof MUCUser)
    {
      MUCUser.Item item = ((MUCUser)obj).getItem();
      
      if (item != null)
      {
        return item.getJid();
      }
    }
  }
  
  return p.getFrom();
}
2. a simpler way
private String getJidFromPresencePacket(Presence p)
{
  MUCUser mucUser = (MUCUser)p.getExtension("x", "http://jabber.org/protocol/muc#user");
  
  if (mucUser != null)
  {
    MUCUser.Item item = mucUser.getItem();
    
    if (item != null)
    {
      return item.getJid();
    }
  }      
  
  return p.getFrom();
}

XMPP JID

A JID consists of three main parts:
  1. The node identifier (optional)
  2. The domain identifier (required)
  3. The resource identifier (optional)

If you want to use only the node id and the domain id in your UI, you can use the method below to extract them from a JID:
StringUtils.parseBareAddress(JID)



Create a Successful Online Store at Bigcommerce! Try it Free Now!