kiu

MUC nickname overwrite

Discussion created by kiu on Feb 28, 2015
Latest reply on Mar 1, 2015 by Flow

On our jabber server we enforce users to have specific nicknames in MUCs (using an authentication system to attach titles to their name).

 

Example: The user peter@example.com needs to join the muc public@conference.example.com with nick "Peter (Director)" or he wont be accepted.

 

Using smack 4.1.0-rc1 on android, the MUC functionality works fine when the user sets the nick to exactly what we expect from that user. Sweet.

But in case the user puts in a wrong nickname (e.g. "peter") when joining the MUC, smacks throws "XMPPError: forbidden - cancel".

 

Which is correct behavior, but the experience delivered by Pidgin is way smoother, it automatically discovers the correct nickname and consequently uses that.

I can manually do that by sending a presence available to the MUC, wait for the response and use the from field to determine the correct nickname, then use MultiUserChat to join (again) with the correct nickname.

 

Presence p = new Presence(Presence.Type.available);

p.setTo("publicd@conference.example.com/peter");

p.setPriority(1);

con.sendPacket(p);

 

<presence to='peter@example.com/resource' from='public@conference.example.com/Peter (Director)' id='RLI5j-5'> ... </presence>

 

I think the code in MultiUserChat should instead of relying on the hardcoded nick:

PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(room + "/" + nickname), new PacketTypeFilter(Presence.class));

should try to set up filters on the nickname which has been acknowledged by the server.

Outcomes