Members cannot get member list in a muc room

↘锁芯ラ 提交于 2019-12-07 08:00:33

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

[Edited 2]:

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

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.

Here is what I did:

  • 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.

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.

[Edited]:

Here is my form when configuring the room:

<x xmlns=\"jabber:x:data\" type=\"form\">
      <title>Configuration of room 1479231695@conference.192.168.100.226</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

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

Let me add my working code in swift, you can check if there is any difference. Sorry couldn't help more.

    func onButtonClicked(_ button: UIButton) {

        let roomJIDStr = theRoomJidStr // get the roomJid
        self.xmppRoom = joinRoom(with: roomJIDStr, delegate: self)
    }

    func joinRoom(with jidString: String, delegate: XMPPRoomDelegate) -> XMPPRoom {

        let roomJID = XMPPJID(string: jidString)
        let roomStorage = XMPPRoomCoreDataStorage.sharedInstance()

        let room = XMPPRoom(roomStorage: roomStorage, jid: roomJID, dispatchQueue: DispatchQueue.main)!

        room.activate(xmppStream)

        room.addDelegate(delegate, delegateQueue: DispatchQueue.main)

        room.join(usingNickname: xmppStream.myJID.user, history: nil)

        return room
    }

    public func xmppRoomDidCreate(_ sender: XMPPRoom!) {
        print("xmppRoomDidCreate")

        // Accept default settings
        let config = DDXMLElement(name: "x", xmlns: "jabber:x:data")
        sender.configureRoom(usingOptions: config)

        // Add members
        let query = DDXMLElement(name: "query", xmlns: XMPPMUCAdminNamespace)
        if let contacts = selectedContacts {

            for c in contacts {

                let item = DDXMLElement(name: "item")
                item.addAttribute(withName: "affiliation", stringValue: "member")
                item.addAttribute(withName: "jid", stringValue: c.xmppAccount!)

                query?.addChild(item)
            }
        }

        let id = XMPPStream.generateUUID()
        let to = sender.roomJID
        let iq = XMPPIQ(type: "set", to: to, elementID: id, child: query)

        chatManager.xmppStream.send(iq)
    }

Preconditions:

  • I set some settings as mod_muc default options, so don't need to configure the room.

    mod_muc: ## host: "conference.@HOST@" access: - allow access_admin: - allow: admin access_create: muc_create access_persistent: muc_create history_size: 0 default_room_options: allow_user_invites: true anonymous: false members_by_default: true members_only: true moderated: false persistent: true public: false public_list: false

  • There is no Invite in my code, I add them directly into member list. And use ejabberd_mod_offline_post for Push Notification. When owner sends the first message, all other members will get the push and start fetching the member list.

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