Create a group chat like whatsapp?

Hi,

I am using smack android rc1. I want to create group chat same as whatsapp. I am confused if i can do it by muc or create group.

I am able to create room with below code.

try {

multiUserChat.create(roomName);

Form form = multiUserChat.getConfigurationForm();

Form submitForm = form.createAnswerForm();

for (FormField formField : form.getFields()) {

if (FormField.Type.hidden.equals(form.getType()) && formField.getVariable() != null) {

submitForm.setDefaultAnswer(formField.getVariable());

}

}

List ownersList = new ArrayList();

ownersList.add(user + “@” + ChatController.HOST);

submitForm.setAnswer(“muc#roomconfig_publicroom”, true);

multiUserChat.sendConfigurationForm(submitForm);

multiUserChat.join(user);

multiUserChat.join(user1);

multiUserChat.join(user2);

List joinedRoomes = multiUserChatManager.getJoinedRooms(xmpptcpConnection.getUser());

for (String jRoomName : joinedRoomes) {

Log.i(Constant.TAG, "Joined room = " + jRoomName);

}

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException e) {

e.printStackTrace();

}

Create group :-

public void addRosterEntry(String jid, String nickname, String group) {

final Roster roster = Roster.getInstanceFor(xmpptcpConnection);

String[] groups = {group};

RosterEntry userEntry = roster.getEntry(jid);

boolean isSubscribed = true;

if (userEntry != null) {

isSubscribed = userEntry.getGroups().isEmpty();

}

if (isSubscribed) {

try {

roster.createEntry(jid, nickname, groups);

} catch (SmackException.NotLoggedInException e) {

e.printStackTrace();

} catch (SmackException.NoResponseException e) {

e.printStackTrace();

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException.NotConnectedException e) {

e.printStackTrace();

}

RosterGroup rosterGroup = roster.getGroup(group);

if (rosterGroup == null) {

rosterGroup = roster.createGroup(group);

if (userEntry == null) {

try {

roster.createEntry(jid, nickname, groups);

userEntry = roster.getEntry(jid);

} catch (SmackException.NotLoggedInException e) {

e.printStackTrace();

} catch (SmackException.NoResponseException e) {

e.printStackTrace();

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException.NotConnectedException e) {

e.printStackTrace();

}

} else {

try {

userEntry.setName(nickname);

rosterGroup.addEntry(userEntry);

} catch (SmackException.NoResponseException e) {

e.printStackTrace();

} catch (XMPPException.XMPPErrorException e) {

e.printStackTrace();

} catch (SmackException.NotConnectedException e) {

e.printStackTrace();

}

}

userEntry = roster.getEntry(jid);

}

}

}

After creating group i am trying to get it by roster.getGroups() but i am not able to get created group.

My requirement is to create group, add contacts to that group and people can chat in that group.

So can anybody please give me some idea to achieve it.

Thanks

1 Like

Ironically, I am also looking for the answer of same question

Actually neither MUC,nor RosterGroups can solve this problem. We need to customize them as per our needs.

May be this will help you

Persistent XMPP MUC (XEP-45), like WhatsApp groupchats - Stack Overflow

Moreover RosterGroups creates groups at client end, for benefit of client it groups contacts. Sending message to this group will send message individually to all its members.

Hi,

@@Hitendrasinh

@@swapnil

I am confused with similarities of group & MUC(groupchat). Conceptually i feel both creating group with more than 1 member is similar to creating MUC with more than 1 member.

I came up with following logic:

1> User mike@example.org creates a group say, ‘song’.

2> Users, dara@example.org and kevin@example.org are also added to ‘song’.

3> I consider a service song@conference.example.org running.

4>I create MUC with above service as the MUC room name.

5>I successfully see messages exchanged between mike,dara,kevin via the room ‘song’.

This is how i bought in 2 concepts into one.

We need an expert to point out if my solution is correct.

@@Hitendrasinh

I have not checked your code.

thanks

Vilpesh