1

I have created a room for group chat. I have created group and added members successfully, but the problem is that members in group are not persisting.The group member get automatically deleted after refreshing.

code :

code : generating jabber id

 private MultiUserChat getMultiUserChat("123456789"){
        MultiUserChatManager manager =  MultiUserChatManager.getInstanceFor(getXmppConnection());
        String jid = "123456789@conference.188.202.110.17";
        return manager.getMultiUserChat(jid);
    }

code : Creating and joining to room

public void createReservedRoom(Context context, String jidName, String roomName, String nickName){

        try {
            connect();

            MultiUserChat muc =  getMultiUserChat(jidName);
            muc.create(nickName);
            try {
                //PreferenceUtils.setObject(context, muc, PreferenceUtils.MUC_OBJ);
            }catch (Exception e){
                e.printStackTrace();
            }
            Form form = getForm(muc, roomName);

            // Send the completed form
            muc.sendConfigurationForm(form);

            muc.join(nickName);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

code : create room

private Form getForm(MultiUserChat muc, String roomName){
        Form form = null;
        try {
            form = muc.getConfigurationForm().createAnswerForm();

            // Create a new form to submit based on the original form
            form.setAnswer("muc#roomconfig_passwordprotectedroom", false);
            form.setAnswer("muc#roomconfig_roomname", roomName);
            form.setAnswer("muc#roomconfig_persistentroom", true);
            form.setAnswer("muc#roomconfig_changesubject", true);
            form.setAnswer("muc#roomconfig_publicroom",true);
            form.setAnswer("muc#roomconfig_allowinvites",true);
            form.setAnswer("muc#roomconfig_membersonly",true);
            form.setAnswer("muc#roomconfig_moderatedroom",false);

            // Sets the new owner of the room
            List<String> owners = new ArrayList<String>();

            //Be carefull: if members does not exists, it brakes!

            owners.add("123456789@conference.188.202.110.17");
            form.setAnswer("muc#roomconfig_roomowners", owners);
        } catch (SmackException.NoResponseException e) {
            e.printStackTrace();
        } catch (XMPPException.XMPPErrorException e) {
            e.printStackTrace();
        } catch (NotConnectedException e) {
            e.printStackTrace();
        }

        return form;
    }
Sumesh B
  • 11
  • 2

1 Answers1

0

Groupchat does not supports "members".

A groupchat can have occupants (people actually joined in session in a groupchat) and Affiliations, users that have a certain role (Owner, Admin, Member and Outcast).

To be a "member" means basically that you are not a moderator (admin) of a chat. But I think you basically want each people you add then automatically join the given groupchat in following sessions, so your users have to SUBSCRIBE the groupchat.

If you want also a whatsapp-like people in groupchat, you can simulate by giving all "admin" affiliation or retrieving all the subscriptions to the given groupchat. It's a large topic...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MrPk
  • 2,862
  • 2
  • 20
  • 26
  • http://xmpp.org/extensions/xep-0045.html. Once i answered more or less how to "hack" the Affiliations to have a persistant member list (of course you'll lose some of native features of Affiliations) http://stackoverflow.com/questions/37431642/create-muc-group-like-whatsapp-android/37434195#37434195 and you can look also http://stackoverflow.com/questions/37524493/smack-presence-listener-in-multi-user-chat/37525135#37525135 (don't forget to vote if anything helps!) -> SMACK docs: http://download.igniterealtime.org/smack/docs/latest/documentation/extensions/muc.html – MrPk Jan 12 '17 at 08:50
  • WRONG, muc support members [members-only room](https://xmpp.org/extensions/attic/xep-0045-1.21.html#enter-members), the thing is you are confusing what a member can do automatically like whatsapp. – MiguelHincapieC Sep 07 '18 at 17:28
  • I suggest to read full answer, what you say it's correct but i already explained in next lines last year ;) – MrPk Sep 10 '18 at 06:33