How to block someone in multiuserchat?

Hi am using smack 4.4. I want to block a user from multi userchat as i can block for contactlist.

for contact list i used

String jid=""
String listName = "blocklist";
        // Create the list of PrivacyItem that will allow or
        // deny some privacy aspect
        List<PrivacyItem> privacyItems = new Vector<>();
        PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid, jid, false, 1);
        // item.setValue(userName);
        // Get the privacy manager for the current connection.
        // Create the new list.
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(BaseApplication.getInstance().connection.getXmpptcpConnection());
        try {
            privacyManager.updatePrivacyList(listName, privacyItems);
            return true;
        } catch (Exception e) {
            Log.e("PRIVACY_ERROR: ", " " + e.toString());
        return false;

if i pass jid ="" then it not worked.
Please let me know what wrong am doing.

Afaict it is not possible on a protocol level to block individual users in a MUC room.
First of all MUC users in anonymous rooms do not possess a “real” jid like “user@server.domain”, but do have a MUC JID instead (“room@conference.server.domain/nickname”). This JID is usually not fixed, eg. it changes when the user changes their nickname, so it doesn’t make sense to block based on that JID.

So I fear that blocking single users in MUC rooms is not possible after all.

Edit: Apparently it is possible to block users based on their MUC JID (muc@conference.server.domain/nickname), but as I wrote earlier this can easily be circumvented by changing the nick.

I understand your concerned but there must be a way to block user from particular chatroom if nickname cannot be changed.
like if block someone in then he cant message me anymore in that chatroom.
But, if i meet him in another room then he unblock there is acceptable.
can we do that?

You may try the “Banning a User” Admin Use case of XEP-0045. For that you must be an admin or owner. In order to ban a user, an admin MUST change the user’s affiliation to “outcast”.

Example 111. Admin Bans User

<iq from='kinghenryv@shakespeare.lit/throne'
<query xmlns=''>
<item affiliation='outcast'

I’ve tried it with Psi and a test room, which I configured manually in the Openfire admin console – by adding the user’s JID to the “Outcast” list.

1 Like

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.