plugins/muc/muc.lib.lua

changeset 2411
c2b6c55201af
parent 2219
838f6d546177
child 2412
e243b7c81de6
--- a/plugins/muc/muc.lib.lua	Sun Dec 27 10:09:22 2009 +0500
+++ b/plugins/muc/muc.lib.lua	Tue Dec 29 16:21:12 2009 -0600
@@ -402,9 +402,23 @@
 			:tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'})
 				:tag("value"):text(self._data.hidden and "0" or "1"):up()
 			:up()
+			:tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'})
+			    :tag("value"):text(self._data.whois or 'moderators'):up()
+			    :tag("option", {label = 'Moderators Only'})
+				:tag("value"):text('moderators'):up()
+				:up()
+			    :tag("option", {label = 'Anyone'})
+				:tag("value"):text('anyone'):up()
+				:up()
+			:up()
 	);
 end
 
+local valid_whois = {
+    moderators = true,
+    anyone = true,
+}
+
 function room_mt:process_form(origin, stanza)
 	local query = stanza.tags[1];
 	local form;
@@ -431,6 +445,14 @@
 	else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end
 	self._data.hidden = not public and true or nil;
 
+	local whois = fields['muc#roomconfig_whois'];
+	if not valid_whois[whois] then
+	    origin.send(st.error_reply(stanza, 'cancel', 'bad-request'));
+	    return;
+	end
+	self._data.whois = whois
+	module:log('debug', 'whois=%s', tostring(whois))
+
 	if self.save then self:save(true); end
 	origin.send(st.reply(stanza));
 end
@@ -735,19 +757,26 @@
 	return true;
 end
 
+local function _get_muc_child(stanza)
+	for i=#stanza.tags,1,-1 do
+		local tag = stanza.tags[i];
+		if tag.name == "x" and tag.attr.xmlns == "http://jabber.org/protocol/muc#user" then
+			return tag;
+		end
+	end
+end
+
 function room_mt:_route_stanza(stanza)
 	local muc_child;
 	local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]];
 	local from_occupant = self._occupants[stanza.attr.from];
 	if stanza.name == "presence" then
 		if to_occupant and from_occupant then
-			if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then
-				for i=#stanza.tags,1,-1 do
-					local tag = stanza.tags[i];
-					if tag.name == "x" and tag.attr.xmlns == "http://jabber.org/protocol/muc#user" then
-						muc_child = tag;
-						break;
-					end
+			if self._data.whois == 'anyone' then
+			    muc_child = _get_muc_child(stanza)
+			else
+				if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then
+					muc_child = _get_muc_child(stanza)
 				end
 			end
 		end
@@ -762,6 +791,9 @@
 				end
 			end
 		end
+		if self._data.whois == 'anyone' then
+		    muc_child:tag('status', { code = '100' });
+		end
 	end
 	self:route_stanza(stanza);
 	if muc_child then
@@ -780,7 +812,9 @@
 		jid = jid;
 		_jid_nick = {};
 		_occupants = {};
-		_data = {};
+		_data = {
+		    whois = 'moderators',
+		};
 		_affiliations = {};
 	}, room_mt);
 end

mercurial