Diff

plugins/muc/muc.lib.lua @ 6250:454ef19e7925

plugins/muc/muc: Better check for live sessions
author daurnimator <quae@daurnimator.com>
date Mon, 19 May 2014 13:40:54 -0400
parent 6249:2420e308f64a
child 6252:10b27981ea3f
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon May 19 13:40:24 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Mon May 19 13:40:54 2014 -0400
@@ -100,11 +100,21 @@
 			self._jid_nick[real_jid] = nil;
 		end
 	end
-	if occupant.role ~= nil and next(occupant.sessions) then
+
+	local has_live_session = false
+	if occupant.role ~= nil then
 		for real_jid, presence in occupant:each_session() do
-			self._jid_nick[real_jid] = occupant.nick;
+			if presence.attr.type == nil then
+				has_live_session = true
+				self._jid_nick[real_jid] = occupant.nick;
+			end
 		end
-	else
+		if not has_live_session then
+			-- Has no live sessions left; they have left the room.
+			occupant.role = nil
+		end
+	end
+	if not has_live_session then
 		occupant = nil
 	end
 	self._occupants[id] = occupant