diff mod_muc_log/mod_muc_log.lua @ 1004:290c21a5e0ee

mod_muc_log, mod_muc_log_http: cleanup syntax (off with the "~= nil"), and cut down wild table indexing.
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 May 2013 02:13:09 +0200
parents 0428009c1127
children b69e5d63a4fe
line wrap: on
line diff
--- a/mod_muc_log/mod_muc_log.lua	Wed May 08 23:30:50 2013 +0100
+++ b/mod_muc_log/mod_muc_log.lua	Thu May 09 02:13:09 2013 +0200
@@ -1,4 +1,5 @@
 local prosody = prosody;
+local hosts = prosody.hosts;
 local tostring = tostring;
 local splitJid = require "util.jid".split;
 local cm = require "core.configmanager";
@@ -36,11 +37,12 @@
 		(stanza.name == "iq") or
 	   	(stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
 	then
-		local node, host, resource = splitJid(stanza.attr.to);
-		if node ~= nil and host ~= nil then
+		local node, host = splitJid(stanza.attr.to);
+		local muc = hosts[host].muc;
+		if node and host then
 			local bare = node .. "@" .. host;
-			if host == mod_host and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then
-				local room = prosody.hosts[host].muc.rooms[bare]
+			if muc and muc.rooms[bare] then
+				local room = muc.rooms[bare]
 				local today = os.date("%y%m%d");
 				local now = os.date("%X")
 				local mucTo = nil
@@ -53,14 +55,14 @@
 				
 				if stanza.name == "presence" and stanza.attr.type == nil then
 					mucFrom = stanza.attr.to;
-					if room._occupants ~= nil and room._occupants[stanza.attr.to] ~= nil then -- if true, the user has already joined the room
+					if room._occupants and room._occupants[stanza.attr.to] then -- if true, the user has already joined the room
 						alreadyJoined = true;
 						stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging
 					end
 				elseif stanza.name == "iq" and stanza.attr.type == "set" then -- kick, to is the room, from is the admin, nick who is kicked is attr of iq->query->item
-					if stanza.tags[1] ~= nil and stanza.tags[1].name == "query" then
+					if stanza.tags[1] and stanza.tags[1].name == "query" then
 						local tmp = stanza.tags[1];
-						if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick ~= nil then
+						if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick then
 							tmp = tmp.tags[1];
 							for jid, nick in pairs(room._jid_nick) do
 								if nick == stanza.attr.to .. "/" .. tmp.attr.nick then
@@ -79,7 +81,7 @@
 					end
 				end
 
-				if (mucFrom ~= nil or mucTo ~= nil) then
+				if (mucFrom or mucTo) then
 					local data = data_load(node, host, datastore .. "/" .. today);
 					local realFrom = stanza.attr.from;
 					local realTo = stanza.attr.to;