Changeset

9315:a47bba3b35f3

MUC: Don't kick user of a reserved nick if it's theirs (thanks pep.)
author Matthew Wild <mwild1@gmail.com>
date Fri, 14 Sep 2018 18:06:12 +0100
parents 9314:c9eef7e8ee65
children 9316:4aa522b9e1c4
files plugins/muc/muc.lib.lua spec/scansion/muc_register.scs
diffstat 2 files changed, 66 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Wed May 16 23:57:09 2018 +0200
+++ b/plugins/muc/muc.lib.lua	Fri Sep 14 18:06:12 2018 +0100
@@ -930,9 +930,12 @@
 		local registration_data;
 		if item.attr.nick then
 			local room_nick = self.jid.."/"..item.attr.nick;
-			if self:get_occupant_by_nick(room_nick) then
+			local existing_occupant = self:get_occupant_by_nick(room_nick);
+			if existing_occupant and existing_occupant.bare_jid ~= item.attr.jid then
+				module:log("debug", "Existing occupant for %s: %s does not match %s", room_nick, existing_occupant.bare_jid, item.attr.jid);
 				self:set_role(true, room_nick, nil, "This nickname is reserved");
 			end
+			module:log("debug", "Reserving %s for %s (%s)", item.attr.nick, item.attr.jid, item.attr.affiliation);
 			registration_data = { reserved_nickname = item.attr.nick };
 		end
 		success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason, registration_data);
--- a/spec/scansion/muc_register.scs	Wed May 16 23:57:09 2018 +0200
+++ b/spec/scansion/muc_register.scs	Fri Sep 14 18:06:12 2018 +0100
@@ -381,3 +381,65 @@
 		</query>
 	</iq>
 
+Juliet sends:
+	<presence type="unavailable" to="room@conference.localhost/Juliet" />
+
+Juliet receives:
+	<presence from='room@conference.localhost/Juliet' type='unavailable' />
+
+Romeo receives:
+	<presence type='unavailable' from='room@conference.localhost/Juliet' />
+
+# Rosaline joins as herself
+
+Rosaline sends:
+	<presence to="room@conference.localhost/Rosaline">
+		<x xmlns="http://jabber.org/protocol/muc"/>
+	</presence>
+
+Rosaline receives:
+	<presence from="room@conference.localhost/Romeo" />
+
+Rosaline receives:
+	<presence from="room@conference.localhost/Rosaline" />
+
+Rosaline receives:
+	<message type='groupchat' from='room@conference.localhost'><subject/></message>
+
+Romeo receives:
+	<presence from='room@conference.localhost/Rosaline'>
+		<x xmlns='http://jabber.org/protocol/muc#user'>
+			<item jid="${Rosaline's full JID}" affiliation='none' role='participant'/>
+		</x>
+	</presence>
+
+# Romeo reserves her nickname for her
+
+Romeo sends:
+	<iq id='member2' to='room@conference.localhost' type='set'>
+		<query xmlns='http://jabber.org/protocol/muc#admin'>
+			<item affiliation='member' jid="${Rosaline's JID}" nick='Rosaline' />
+		</query>
+	</iq>
+
+Romeo receives:
+	<presence from='room@conference.localhost/Rosaline'>
+		<x xmlns='http://jabber.org/protocol/muc#user'>
+			<item affiliation='member' role='participant' jid="${Rosaline's full JID}">
+				<actor jid="${Romeo's full JID}" nick='Romeo'/>
+			</item>
+		</x>
+	</presence>
+
+Romeo receives:
+	<iq type='result' id='member2' from='room@conference.localhost' />
+
+Rosaline receives:
+	<presence from='room@conference.localhost/Rosaline'>
+		<x xmlns='http://jabber.org/protocol/muc#user'>
+			<item affiliation='member' role='participant' jid="${Rosaline's full JID}">
+				<actor nick='Romeo' />
+			</item>
+			<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>
+		</x>
+	</presence>