创建类似whatsapp Android的MUC组 [英] Create MUC group like whatsapp Android

查看:96
本文介绍了创建类似whatsapp Android的MUC组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建并加入MUC会议室.但是用户断开与Openfire服务器的连接,将其从服务器端的组中删除.我该如何类似于Whatsapp所做的事情,即即使用户下线,他仍然是MUC机房的一部分(配置为在服务器端永久存在),并且将接收来自其他占用者的消息.

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.

推荐答案

邀请用户时,您必须授予其成员资格:

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;
    }

因此,您将获得与该会议室关联的所有用户的列表. 您可以在某些回调中使用此列表来制作所有成员"列表,例如在WhatsApp中.

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.

查看此页面的末尾: https://www.igniterealtime.org/builds/smack/dailybuilds /documentation/extensions/muc.html

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

(不要忘记投票!)

这篇关于创建类似whatsapp Android的MUC组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆