Changeset

7706:d92e186c2a1c

MUC: Include the appropriate status code if nickname is changed during join process
author Kim Alvefur <zash@zash.se>
date Wed, 26 Oct 2016 13:10:22 +0200
parents 7705:0a29a5e64f1d
children 7707:7bb1cc7278b6
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Wed Oct 26 13:06:08 2016 +0200
+++ b/plugins/muc/muc.lib.lua	Wed Oct 26 13:10:22 2016 +0200
@@ -402,6 +402,7 @@
 		module:log("debug", "Room creation without <x>, possibly desynced");
 	end
 
+	local orig_nick = dest_occupant.nick;
 	if module:fire_event("muc-occupant-pre-join", {
 		room = self;
 		origin = origin;
@@ -410,6 +411,7 @@
 		is_new_room = true;
 		occupant = dest_occupant;
 	}) then return true; end
+	local nick_changed = orig_nick ~= dest_occupant.nick;
 
 	dest_occupant:set_session(real_jid, stanza);
 	local dest_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";});
@@ -417,9 +419,14 @@
 	if self:get_whois() == "anyone" then
 		dest_x:tag("status", {code = "100"}):up();
 	end
+	local self_x;
+	if nick_changed then
+		self_x = st.clone(dest_x);
+		self_x:tag("status", {code = "210"}):up();
+	end
 	self:save_occupant(dest_occupant);
 
-	self:publicise_occupant_status(dest_occupant, dest_x);
+	self:publicise_occupant_status(dest_occupant, {base = dest_x, self = self_x});
 
 	module:fire_event("muc-occupant-joined", {
 		room = self;
@@ -485,6 +492,8 @@
 		module:log("debug", "Presence update with <x>, possibly desynced");
 	end
 
+	local orig_nick = dest_occupant and dest_occupant.nick;
+
 	local event, event_name = {
 		room = self;
 		origin = origin;
@@ -505,6 +514,8 @@
 	end
 	if module:fire_event(event_name, event) then return true; end
 
+	local nick_changed = dest_occupant and orig_nick ~= dest_occupant.nick;
+
 	-- Check for nick conflicts
 	if dest_occupant ~= nil and not is_first_dest_session and bare_jid ~= jid_bare(dest_occupant.bare_jid) then -- new nick or has different bare real jid
 		log("debug", "%s couldn't join due to nick conflict: %s", real_jid, dest_occupant.nick);
@@ -586,7 +597,12 @@
 				return occupant:get_presence(real_jid) == nil;
 			end)
 		end
-		self:publicise_occupant_status(dest_occupant, dest_x);
+		local self_x;
+		if nick_changed then
+			self_x = st.clone(dest_x);
+			self_x:tag("status", {code="210"}):up();
+		end
+		self:publicise_occupant_status(dest_occupant, {base=dest_x,self=self_x});
 
 		if orig_occupant ~= nil and orig_occupant ~= dest_occupant and not is_last_orig_session then -- If user is swapping and wasn't last original session
 			log("debug", "session %s split nicks; showing %s rejoining", real_jid, orig_occupant.nick);