【问题标题】:How to get MUC room list which a user already participated?如何获取用户已经参与的 MUC 房间列表?
【发布时间】:2019-03-06 04:29:52
【问题描述】:

我正在使用 MUC 通过 smack 进行群聊。我想获取用户已经参与的 MUC 房间列表,例如 whatsapp。

使用 belove 代码,我只获得用户加入的房间,但我需要获得我已经成为成员的所有组。

这是我的代码:

 List<EntityBareJid> joinedRoomes = manager.getJoinedRooms(conn);

            for (EntityBareJid jRoomName : joinedRoomes) {

                Log.e("Group Chat : Joined room = " , jRoomName.toString());

            }

有人帮帮我吗?

我还想为 MUC 组添加头像图像。我该怎么做?

【问题讨论】:

    标签: android xmpp ejabberd asmack multiuserchat


    【解决方案1】:

    您可以尝试这种方式获取组员和详细信息

     public static List<String> getRoomInfo(String grp_id) {
        List<String> jids = new ArrayList<>();
        try {
    
    
            EntityBareJid mucJid = JidCreate.entityBareFrom(grp_id + "@" + Constants.GRP_SERVICE);
    
    
            mucChatManager = MultiUserChatManager.getInstanceFor(MyApplication.connection);
            mucChat = mucChatManager.getMultiUserChat(mucJid);
    
            RoomInfo info = mucChatManager.getRoomInfo(mucJid);
    
    
            LogM.e("Number of occupants:" + info.getOccupantsCount());
            LogM.e("Room Subject:" + info.getSubject());
    
            Log.e(TAG, "members " + mucChat.getMembers().size());
    
            List<Affiliate> affiliatesMembers = mucChat.getMembers();
    
    
            Log.e(TAG, "members1 " + affiliatesMembers.size());
            for (Affiliate affiliate : affiliatesMembers) {
                Log.e(TAG, "members: Jid:" + affiliate.getJid()
    
                );
                if (affiliate.getJid() != null) {
                    jids.add(affiliate.getJid().toString());
                }
            }
            return jids;
    
        } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | XmppStringprepException e) {
            Log.e(TAG, "Group Error : " + e.getMessage());
    
        } catch (SmackException.NotConnectedException e) {
            Log.e(TAG, "Group Error2 : " + e.getMessage());
    
        }
        return jids;
    }
    

    【讨论】:

      【解决方案2】:

      没有命令可以获取帐户为成员/管理员/所有者的房间列表...只有一个命令可以获取特定房间的从属关系列表。

      我还想为 MUC 组添加头像图像。我该怎么做?

      房间没有电子名片,所以没有地方存储图像。但它有一个“描述”字段,您可以在其中放置头像图像的 URL,然后修改客户端以读取该 URL 并将图像显示为房间头像。

      【讨论】:

        猜你喜欢
        • 2017-04-01
        • 2014-04-08
        • 2017-03-27
        • 1970-01-01
        • 2012-09-13
        • 1970-01-01
        • 2011-10-10
        • 1970-01-01
        相关资源
        最近更新 更多