# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1461084367 -7200
# Node ID e49737de98729c5082376f41a72662b5fbff9a72
# Parent  71a7140200fc5957b90f2f588e750d6d4c1c7b76
MUC: Fix logic for when to broadcast unavailable presence (actual fix for 14170d161b39)

diff -r 71a7140200fc -r e49737de9872 plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Tue Apr 19 18:43:15 2016 +0200
+++ b/plugins/muc/muc.lib.lua	Tue Apr 19 18:46:07 2016 +0200
@@ -196,7 +196,7 @@
 	local base_presence do
 		-- Try to use main jid's presence
 		local pr = occupant:get_presence();
-		if pr and (pr.attr.type ~= "unavailable" or occupant.role == nil) then
+		if pr and (pr.attr.type ~= "unavailable" and occupant.role ~= nil) then
 			base_presence = st.clone(pr);
 		else -- user is leaving but didn't send a leave presence. make one for them
 			base_presence = st.presence {from = occupant.nick; type = "unavailable";};
@@ -737,7 +737,6 @@
 		occupants_updated[occupant] = true;
 	end
 	for occupant in pairs(occupants_updated) do
-		occupant:set_session(occupant.jid, st.presence({type="unavailable"}), true);
 		self:publicise_occupant_status(occupant, x);
 		module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;});
 	end