本文介绍了会员无法在Muc会议室中获取会员列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将IOS XMPPFramework用于我们的聊天应用程序,并且正在创建组并使用以下代码添加所选成员,并且接收者成功加入了该组.而且,如果我查询该组管理员的成员列表,则会成功检索该组的成员,但成员无法获取相同的列表,而是收到以下错误:

I'm using IOS XMPPFramework for our chat application and I'm creating the group and adding the selected member with the below code, and receipants succesfully joins the group.And if I query the member list of that group admins succesfully retrieve the group's members but members cannot get the same list and instead they are receiving the below error:

<iq xmlns="jabber:client" from="[email protected]" to="[email protected]/15323458207749806891286" id="FF691FF5-D12B-4BAA-AB19-84E7A2B945D4" type="error"><query xmlns="http://jabber.org/protocol/muc#admin"><item affiliation="member"/></query><error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Administrator privileges required</text></error></iq>

您可以在下面找到创建和邀请代码:

You can find the create and invite codes below:

- (void)xmppRoom:(XMPPRoom*)sender didFetchMembersList:(NSArray *)items
{
    CLS_LOG(@"Received MemberList: %@",items);
    if (sender.inviteMemberList) {
        if ([sender.inviteMemberList count]) {

            for (NSString *user in sender.inviteMemberList) {
                [sender inviteUser:[XMPPJID jidWithString:user] withMessage:nil];
            }


            CLS_LOG(@"Adding Members To Group %@",sender.inviteMemberList);
            XMPPIQ *addMemberIQ = [XMPPIQ addMembersToGroup:sender.inviteMemberList withElementId:[self generateMessageID] andNick:sender.nickName andGroupJid:[sender.roomJID bare]];
            CLS_LOG(@"Sending IQ To Add Member: %@",addMemberIQ);
            [xmppStream sendElement:addMemberIQ];
            sender.inviteMemberList = nil;
        }
    }


}

+ (nonnull instancetype) addMembersToGroup:(NSArray *)memberList withElementId:(NSString*)elementId andNick:(NSString*)nick andGroupJid:(NSString*)groupJid
{
    NSXMLElement *queryElement = [self elementWithName:@"query" xmlns:XMPPMUCAdminNamespace];

    for (NSString *member in memberList) {
        NSXMLElement *itemElement = [self elementWithName:@"item"];
        [itemElement addAttributeWithName:@"affiliation" stringValue:@"member"];
        [itemElement addAttributeWithName:@"jid" stringValue:member];

        [queryElement addChild:itemElement];
    }


    return [self iqWithType:@"set" to:[XMPPJID jidWithString:groupJid] elementID:elementId child:queryElement];
}

您还可以在下面的xml中找到我的房间配置:

You can also find my room config in the below xml:

<?xml version="1.0" encoding="UTF-8"?>
<x xmlns="jabber:x:data" type="form">
   <title>Configuration of room [email protected]</title>
   <field type="hidden" var="FORM_TYPE">
      <value>http://jabber.org/protocol/muc#roomconfig</value>
   </field>
   <field type="text-single" label="Room title" var="muc#roomconfig_roomname">
      <value>osmannn</value>
   </field>
   <field type="text-single" label="Room description" var="muc#roomconfig_roomdesc">
      <value />
   </field>
   <field type="boolean" label="Make room persistent" var="muc#roomconfig_persistentroom">
      <value>1</value>
   </field>
   <field type="boolean" label="Make room public searchable" var="muc#roomconfig_publicroom">
      <value>1</value>
   </field>
   <field type="boolean" label="Make participants list public" var="public_list">
      <value>1</value>
   </field>
   <field type="boolean" label="Make room password protected" var="muc#roomconfig_passwordprotectedroom">
      <value>0</value>
   </field>
   <field type="text-private" label="Password" var="muc#roomconfig_roomsecret">
      <value />
   </field>
   <field type="list-single" label="Maximum Number of Occupants" var="muc#roomconfig_maxusers">
      <value>200</value>
      <option label="5">
         <value>5</value>
      </option>
      <option label="10">
         <value>10</value>
      </option>
      <option label="20">
         <value>20</value>
      </option>
      <option label="30">
         <value>30</value>
      </option>
      <option label="50">
         <value>50</value>
      </option>
      <option label="100">
         <value>100</value>
      </option>
      <option label="200">
         <value>200</value>
      </option>
   </field>
   <field type="list-single" label="Present real Jabber IDs to" var="muc#roomconfig_whois">
      <value>anyone</value>
      <option label="moderators only">
         <value>moderators</value>
      </option>
      <option label="anyone">
         <value>anyone</value>
      </option>
   </field>
   <field type="list-multi" label="Roles for which Presence is Broadcasted" var="muc#roomconfig_presencebroadcast">
      <value>moderator</value>
      <value>participant</value>
      <value>visitor</value>
      <option label="Moderator">
         <value>moderator</value>
      </option>
      <option label="Participant">
         <value>participant</value>
      </option>
      <option label="Visitor">
         <value>visitor</value>
      </option>
   </field>
   <field type="boolean" label="Make room members-only" var="muc#roomconfig_membersonly">
      <value>1</value>
   </field>
   <field type="boolean" label="Make room moderated" var="muc#roomconfig_moderatedroom">
      <value>1</value>
   </field>
   <field type="boolean" label="Default users as participants" var="members_by_default">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow users to change the subject" var="muc#roomconfig_changesubject">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow users to send private messages" var="allow_private_messages">
      <value>1</value>
   </field>
   <field type="list-single" label="Allow visitors to send private messages to" var="allow_private_messages_from_visitors">
      <value>anyone</value>
      <option label="nobody">
         <value>nobody</value>
      </option>
      <option label="moderators only">
         <value>moderators</value>
      </option>
      <option label="anyone">
         <value>anyone</value>
      </option>
   </field>
   <field type="boolean" label="Allow users to query other users" var="allow_query_users">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow users to send invites" var="muc#roomconfig_allowinvites">
      <value>0</value>
   </field>
   <field type="boolean" label="Allow visitors to send status text in presence updates" var="muc#roomconfig_allowvisitorstatus">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow visitors to change nickname" var="muc#roomconfig_allowvisitornickchange">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow visitors to send voice requests" var="muc#roomconfig_allowvoicerequests">
      <value>1</value>
   </field>
   <field type="boolean" label="Allow subscription" var="muc#roomconfig_allow_subscription">
      <value>1</value>
   </field>
   <field type="text-single" label="Minimum interval between voice requests (in seconds)" var="muc#roomconfig_voicerequestmininterval">
      <value>1800</value>
   </field>
   <field type="jid-multi" label="Exclude Jabber IDs from CAPTCHA challenge" var="muc#roomconfig_captcha_whitelist" />
</x>

您能帮我解决这个问题吗?

Can you help me with that problem?

我已经像下面的代码一样更改了代码.我也使配置与您相同,但结果仍然相同.我在服务器端缺少某些内容吗?

I've changed my code like in the below code. And I also made the configuration same with you, But still the same result. Am I missing something in server side ?

- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm{

        NSXMLElement *newConfig = [configForm copy];
        NSArray* fields = [newConfig elementsForName:@"field"];
        for (NSXMLElement *field in fields) {
            NSString *var = [field attributeStringValueForName:@"var"];

            if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) {
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];

            }else if ([var isEqualToString:@"muc#roomconfig_roomname"]){
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:sender.groupName]];

            }
            else if ([var isEqualToString:@"muc#roomconfig_publicroom"]){
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"0"]];
            }
            else if ([var isEqualToString:@"muc#roomconfig_whois"]) {
                [field removeChildAtIndex:0];
                [field insertChild:[NSXMLElement elementWithName:@"value" stringValue:@"anyone"] atIndex:0];
            }
            else if ([var isEqualToString:@"muc#roomconfig_allow_subscription"]) {
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
            }
            else if ([var isEqualToString:@"muc#roomconfig_membersonly"]){
              [field removeChildAtIndex:0];
              [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
            }
            else if ([var isEqualToString:@"public_list"]){
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
            }
            else if ([var isEqualToString:@"muc#roomconfig_allowinvites"]){
                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
            }
        }
        CLS_LOG(@"Sending Configuration: %@",newConfig);
        [sender configureRoomUsingOptions:newConfig];


        if (sender.inviteMemberList) {
            CLS_LOG(@"Adding Members To Group %@",sender.inviteMemberList);
            XMPPIQ *addMemberIQ = [XMPPIQ addMembersToGroup:sender.inviteMemberList withElementId:[self generateMessageID] andNick:sender.nickName andGroupJid:[sender.roomJID bare]];
            CLS_LOG(@"Sending IQ To Add Member: %@",addMemberIQ);
            [xmppStream sendElement:addMemberIQ];
            [sender fetchMembersList];

        }

}

- (void)xmppRoom:(XMPPRoom*)sender didFetchMembersList:(NSArray *)items{

    CLS_LOG(@"Fetched Members: %@",items);

    if (sender.inviteMemberList) {
        if ([sender.inviteMemberList count]) {

            for (NSString *user in sender.inviteMemberList) {
                [sender inviteUser:[XMPPJID jidWithString:user] withMessage:nil];
            }


            sender.inviteMemberList = nil;
        }
    }

}

推荐答案

在配置会议室时,请确保将muc#roomconfig_whois设置为anyone.

Make sure you set the muc#roomconfig_whois to anyone when configuring the room.

 <field
          label='Who May Discover Real JIDs?'
          type='list-single'
          var='muc#roomconfig_whois'>
        <option label='Moderators Only'>
          <value>moderators</value>
        </option>
        <option label='Anyone'>
          <value>anyone</value>
        </option>
  </field>

http://xmpp.org/extensions/xep-0045.html#roomconfig

:

我想我想弄清楚什么地方出了问题.从您的代码中,您首先邀请了用户,然后将其添加到成员中.

I guess I kinna figure out what was wrong. From your code, you invited users first, then add them to members.

您可以尝试逆转流程吗?首先将所有成员添加到成员,然后邀请.否则,当用户收到邀请时,可能尚未在Xmpp Server上设置成员.

Could you try reverse the flow. Add all to members first, and then invite. Otherwise when a user gets the invitation, the members might not be set on Xmpp Server yet.

这是我所做的:

  • 加入一个房间,(如果房间不存在,服务器将创建它).
  • 在xmppRoomDidCreate中,获取配置表单.
  • 发送配置表单,然后紧随添加所有成员.
  • 在didConfigure中,发送邀请.
  • Join a room, (if the room is not existing, server will create it).
  • In xmppRoomDidCreate, fetch config form.
  • Send the config form, and Add All Members right after.
  • In didConfigure, send invitations.

流程有点慢,我建议您将设置作为默认设置添加到mod_muc中.只需确保添加成员,然后再发送邀请即可.

The flow is kind of slow, I suggest you add the settings as default settings in mod_muc. Just make sure add members before send invitation.

[已编辑]:

这是配置房间时的表格:

Here is my form when configuring the room:

<x xmlns=\"jabber:x:data\" type=\"form\">
      <title>Configuration of room [email protected]</title>
      <field type=\"hidden\" var=\"FORM_TYPE\">
        <value>http://jabber.org/protocol/muc#roomconfig</value>
      </field>
      <field type=\"text-single\" label=\"Room title\" var=\"muc#roomconfig_roomname\">
        <value></value>
      </field>
      <field type=\"text-single\" label=\"Room description\" var=\"muc#roomconfig_roomdesc\">
        <value></value>
      </field>
      <field type=\"boolean\" label=\"Make room persistent\" var=\"muc#roomconfig_persistentroom\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Make room public searchable\" var=\"muc#roomconfig_publicroom\">
        <value>0</value>
      </field>
      <field type=\"boolean\" label=\"Make participants list public\" var=\"public_list\">
        <value>0</value>
      </field>
      <field type=\"boolean\" label=\"Make room password protected\" var=\"muc#roomconfig_passwordprotectedroom\">
        <value>0</value>
      </field>
      <field type=\"text-private\" label=\"Password\" var=\"muc#roomconfig_roomsecret\">
        <value></value>
      </field>
      <field type=\"list-single\" label=\"Maximum Number of Occupants\" var=\"muc#roomconfig_maxusers\">
        <value>200</value>
        <option label=\"5\">
          <value>5</value>
        </option>
        <option label=\"10\">
          <value>10</value>
        </option>
        <option label=\"20\">
          <value>20</value>
        </option>
        <option label=\"30\">
          <value>30</value>
        </option>
        <option label=\"50\">
          <value>50</value>
        </option>
        <option label=\"100\">
          <value>100</value>
        </option>
        <option label=\"200\">
          <value>200</value>
        </option>
      </field>
      <field type=\"list-single\" label=\"Present real Jabber IDs to\" var=\"muc#roomconfig_whois\">
        <option label=\"moderators only\">
          <value>moderators</value>
        </option>
        <option label=\"anyone\">
          <value>anyone</value>
        </option>
        <value>anyone</value>
      </field>
      <field type=\"list-multi\" label=\"Roles for which Presence is Broadcasted\" var=\"muc#roomconfig_presencebroadcast\">
        <value>moderator</value>
        <value>participant</value>
        <value>visitor</value>
        <option label=\"Moderator\">
          <value>moderator</value>
        </option>
        <option label=\"Participant\">
          <value>participant</value>
        </option>
        <option label=\"Visitor\">
          <value>visitor</value>
        </option>
      </field>
      <field type=\"boolean\" label=\"Make room members-only\" var=\"muc#roomconfig_membersonly\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Make room moderated\" var=\"muc#roomconfig_moderatedroom\">
        <value>0</value>
      </field>
      <field type=\"boolean\" label=\"Default users as participants\" var=\"members_by_default\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow users to change the subject\" var=\"muc#roomconfig_changesubject\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow users to send private messages\" var=\"allow_private_messages\">
        <value>1</value>
      </field>
      <field type=\"list-single\" label=\"Allow visitors to send private messages to\" var=\"allow_private_messages_from_visitors\">
        <value>anyone</value>
        <option label=\"nobody\">
          <value>nobody</value>
        </option>
        <option label=\"moderators only\">
          <value>moderators</value>
        </option>
        <option label=\"anyone\">
          <value>anyone</value>
        </option>
      </field>
      <field type=\"boolean\" label=\"Allow users to query other users\" var=\"allow_query_users\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow users to send invites\" var=\"muc#roomconfig_allowinvites\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow visitors to send status text in presence updates\" var=\"muc#roomconfig_allowvisitorstatus\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow visitors to change nickname\" var=\"muc#roomconfig_allowvisitornickchange\">
        <value>1</value>
      </field>
      <field type=\"boolean\" label=\"Allow visitors to send voice requests\" var=\"muc#roomconfig_allowvoicerequests\">
        <value>1</value>
      </field>
      <field type=\"text-single\" label=\"Minimum interval between voice requests (in seconds)\" var=\"muc#roomconfig_voicerequestmininterval\">
        <value>1800</value>
      </field>
      <field type=\"jid-multi\" label=\"Exclude Jabber IDs from CAPTCHA challenge\" var=\"muc#roomconfig_captcha_whitelist\"></field>
    </x>

如您所见,项目之间存在一些差异:

As you can see, there is some differences on the items:

  • muc#roomconfig_publicroom
  • public_list
  • muc#roomconfig_moderatedroom
  • muc#roomconfig_allowinvites

我尝试将"muc#roomconfig_moderatedroom"设置为1,但所有成员都可以获取成员列表.不知道你身边发生了什么.

I tried set the "muc#roomconfig_moderatedroom" to 1, still all members can get the members list. Not sure what happened on your side.

这篇关于会员无法在Muc会议室中获取会员列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 19:41