Create MUC group like whatsapp Android

痴心易碎 提交于 2019-12-14 03:33:29

问题


I can creating and joining MUC rooms. But user disconnects from the Openfire server, he is removed from the group on the server side. How can i similar to what Whatsapp does, i.e. even if the user goes offline, he is still part of the MUC room (which is configured to be persistent on the server side) and will receive messages from other occupants.


回答1:


When inviting an user, you have to grant him Membership:

MultiUserChat muc = multiUserChatManager.getMultiUserChat("foo@conference.myserver");

muc.invite("jhondoe@myserver","Join this groupchat!");

then you can grant him voice and you must grantMembership (or Ownership or Moderation as you like/need):

muc.grantVoice("jhondoe@myserver");
muc.grantMembership("jhondoe@myserver");

finally you have to integrate a list like that with your client:

public List<String> retriveAllAffialiateOfMuc(MultiUserChat muc) throws NoResponseException, XMPPErrorException, NotConnectedException
    {
        List<Affiliate> affiliatesMembers = new ArrayList<Affiliate>();
        if (muc.getAdmins() != null)
        {
            affiliatesMembers.addAll( muc.getAdmins() );
        }

        if ( muc.getMembers() != null)
        {
            affiliatesMembers.addAll( muc.getMembers() );
        }

        if ( muc.getOwners() != null )
        {
            affiliatesMembers.addAll( muc.getOwners() );
        }

        if (affiliatesMembers.size() == 0)
        {
            System.out.println("Error: looking for a non existant room");
            return  new ArrayList<String>(0);
        }

        List<String> affiliateMembersNames = new ArrayList<String>(affiliatesMembers.size());

        for (Affiliate affiliate : affiliatesMembers)
        {
            affiliateMembersNames.add(affiliate.getJid().toString());
        }
        return affiliateMembersNames;
    }

So you'll have a list of all users affiliate to the room. You can use this list in some callback to make a list of "all members" like in WhatsApp.

Look at the end of this page: https://www.igniterealtime.org/builds/smack/dailybuilds/documentation/extensions/muc.html

(dont' forget to vote!)



来源:https://stackoverflow.com/questions/37431642/create-muc-group-like-whatsapp-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!