mod_muc: Add getter/setter for 'whois' (fixes traceback)
authorMatthew Wild <mwild1@gmail.com>
Sat, 18 May 2013 15:28:00 +0100
changeset 5600 1b326a1e4da6
parent 5595 b9c836dc8f2a
child 5601 f55ab5fa939f
mod_muc: Add getter/setter for 'whois' (fixes traceback)
plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Sat May 18 12:03:03 2013 +0100
+++ b/plugins/muc/muc.lib.lua	Sat May 18 15:28:00 2013 +0100
@@ -357,6 +357,19 @@
 end
 
 
+local valid_whois = { moderators = true, anyone = true };
+
+function room_mt:set_whois(whois)
+	if valid_whois[whois] and self._data.whois ~= whois then
+		self._data.whois = whois;
+		if self.save then self:save(true); end
+	end
+end
+
+function room_mt:get_whois()
+	return self._data.whois;
+end
+
 local function construct_stanza_id(room, stanza)
 	local from_jid, to_nick = stanza.attr.from, stanza.attr.to;
 	local from_nick = room._jid_nick[from_jid];
@@ -661,8 +674,6 @@
 	return module:fire_event("muc-config-form", { room = self, form = form }) or form;
 end
 
-local valid_whois = { moderators = true, anyone = true };
-
 function room_mt:process_form(origin, stanza)
 	local query = stanza.tags[1];
 	local form;
@@ -708,7 +719,7 @@
 			:tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up()
 				:tag('status', {code = '104'}):up();
 		if changed.whois then
-			local code = (whois == 'moderators') and "173" or "172";
+			local code = (self:get_whois() == 'moderators') and "173" or "172";
 			msg.tags[1]:tag('status', {code = code}):up();
 		end
 		self:broadcast_message(msg, false)