Instant messenger question

Hi there

I’‘m developing a small instant messenger app. I have a listener for incomming messages. Once a message arrives, I’'m checking the thread id of the chat and send the message to the appropriate Conversation (a Object to store messages, the observable for the Chat gui). I also store chat Objects, If the chat object does not yet exist on the arrival fo a message, I create it and store it with the same thread id as the incomming message, so i have control which message goes to which conversation. BUT: When i create the chat object, I need to supply it with the user… so I thought i could take the From parameter from the incomming message, but the format is different:

Message From: largo@blue/Smack

What i Need: largo@blue

Am I going the wrong way with my app? Can I process these messages somehow differently?

You could use the StringUtils method

StringUtils.parseBareAddress(jid);

in order to retrieve the address of the contact minus any resource information

Note that there’'s a difference between contacts on the roster and contacts that are online. You will always chat with a jid that contains a resource, so it might be a good idea to store the resource along with the ongoing chat.

In my client, there’‘s a hierarchy: The contacts on the roster don’‘t have a presence state, but they can contain other items that are online and have a presence. This way I can even chat to both blah@blah.com/Smack1 and blah@blah.com/Smack2 at the same time, and they don’'t interfere.

I tried this in my MultiUserChat and it returns the name of the chat room.

I ended up creating a parse method but I would rather use the built in smack utilities.

Any suggestions on how to get the occupant name?

This is what I am doing:

++

PacketListener muccListener = new PacketListener()

{

public void processPacket(Packet packet)

{

Message message = (Message)packet;

messageBuffer.append(StringUtils.parseName(message.getFrom())message.getBody()"
");

}

};

TIA!

I wrote some utility methods to split the three parts (user, host and resource), it’'s very simple. MUCs use the format chatroom@host/nick.

Yeah like Anlumo said the easiest way would be to just parse out the part you need that is what I did. For example:

String userName= message.getFrom();

userName= userName.substring(0, userName.indexOf(’’/’’));

Something to that effect should work.

E

Message was edited by: the.eagle

Message was edited by: the.eagle

Message was edited by: the.eagle

Message was edited by: the.eagle

Though using the pre-built methods in the StringUtils class means you dont have to roll your own