i am working on chat app based on XMPP in Android.
i have done one to one chat functionality, but having some problem in multi user chat.
i have successfully created new chat room, multiple users can join that room.
i have also written code for addPacketListener
for Group chat with PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
i also receiving messages in that listener when user sents message in group, but i am unable to distinguish which user has sent message.
like one to one chat message packet has function message.getFrom()
to retrieve senders JID.
in case of multi user chat, same function returns the group/room JID as sender.
i have also tried to set property of Message while sending message.setFrom(senderJID);
or message.setFrom([email protected]/Groupname);
still i am unable to get senderJID or its nickname.
so my question is: how to get sender user JID or its nickname? from message(packet) in messageListener
Code for sending msg in group is:-
String to = strGroupJID;
String text = etChatOnTextBox.getText().toString();
if(!text.equals(""))
{
Message msg = new Message(to, Message.Type.groupchat);
msg.setBody(text);
String name1 = xmppConnection.getUser();
name1 = name1.substring(0, name1.lastIndexOf("@"));
name1 = name1 + "@conference.192.168.56.1";
// name1 = name1 + "@conference.192.168.56.1/" + strGroupName ;
msg.setFrom(name1);
muc.sendMessage(msg);
}
Code for Receive Message is:-
PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
connection.addPacketListener(new PacketListener() {
@Override
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message
.getFrom());
Log.i("ChatOn", "Text Recieved " + message.getBody()
+ " from " + fromName );
}
}
});
any help or suggestion is appreciated thank you