comparison 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
comparison
equal deleted inserted replaced
1003:767999c39f0a 1004:290c21a5e0ee
1 local prosody = prosody; 1 local prosody = prosody;
2 local hosts = prosody.hosts;
2 local tostring = tostring; 3 local tostring = tostring;
3 local splitJid = require "util.jid".split; 4 local splitJid = require "util.jid".split;
4 local cm = require "core.configmanager"; 5 local cm = require "core.configmanager";
5 local datamanager = require "util.datamanager"; 6 local datamanager = require "util.datamanager";
6 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; 7 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath;
34 35
35 if (stanza.name == "presence") or 36 if (stanza.name == "presence") or
36 (stanza.name == "iq") or 37 (stanza.name == "iq") or
37 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") 38 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
38 then 39 then
39 local node, host, resource = splitJid(stanza.attr.to); 40 local node, host = splitJid(stanza.attr.to);
40 if node ~= nil and host ~= nil then 41 local muc = hosts[host].muc;
42 if node and host then
41 local bare = node .. "@" .. host; 43 local bare = node .. "@" .. host;
42 if host == mod_host and prosody.hosts[host] ~= nil and prosody.hosts[host].muc ~= nil and prosody.hosts[host].muc.rooms[bare] ~= nil then 44 if muc and muc.rooms[bare] then
43 local room = prosody.hosts[host].muc.rooms[bare] 45 local room = muc.rooms[bare]
44 local today = os.date("%y%m%d"); 46 local today = os.date("%y%m%d");
45 local now = os.date("%X") 47 local now = os.date("%X")
46 local mucTo = nil 48 local mucTo = nil
47 local mucFrom = nil; 49 local mucFrom = nil;
48 local alreadyJoined = false; 50 local alreadyJoined = false;
51 return; 53 return;
52 end 54 end
53 55
54 if stanza.name == "presence" and stanza.attr.type == nil then 56 if stanza.name == "presence" and stanza.attr.type == nil then
55 mucFrom = stanza.attr.to; 57 mucFrom = stanza.attr.to;
56 if room._occupants ~= nil and room._occupants[stanza.attr.to] ~= nil then -- if true, the user has already joined the room 58 if room._occupants and room._occupants[stanza.attr.to] then -- if true, the user has already joined the room
57 alreadyJoined = true; 59 alreadyJoined = true;
58 stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging 60 stanza:tag("alreadyJoined"):text("true"); -- we need to log the information that the user has already joined, so add this and remove after logging
59 end 61 end
60 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 62 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
61 if stanza.tags[1] ~= nil and stanza.tags[1].name == "query" then 63 if stanza.tags[1] and stanza.tags[1].name == "query" then
62 local tmp = stanza.tags[1]; 64 local tmp = stanza.tags[1];
63 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick ~= nil then 65 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick then
64 tmp = tmp.tags[1]; 66 tmp = tmp.tags[1];
65 for jid, nick in pairs(room._jid_nick) do 67 for jid, nick in pairs(room._jid_nick) do
66 if nick == stanza.attr.to .. "/" .. tmp.attr.nick then 68 if nick == stanza.attr.to .. "/" .. tmp.attr.nick then
67 mucTo = nick; 69 mucTo = nick;
68 break; 70 break;
77 break; 79 break;
78 end 80 end
79 end 81 end
80 end 82 end
81 83
82 if (mucFrom ~= nil or mucTo ~= nil) then 84 if (mucFrom or mucTo) then
83 local data = data_load(node, host, datastore .. "/" .. today); 85 local data = data_load(node, host, datastore .. "/" .. today);
84 local realFrom = stanza.attr.from; 86 local realFrom = stanza.attr.from;
85 local realTo = stanza.attr.to; 87 local realTo = stanza.attr.to;
86 88
87 if data == nil then 89 if data == nil then