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:- The node identifier (optional)
- The domain identifier (required)
- 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)