diff mod_muc_log/mod_muc_log.lua @ 1450:5107278268ae

mod_muc_log, mod_muc_log_http: Make compatible with both new and old MUC API
author Vadim Misbakh-Soloviov <mva@mva.name>
date Tue, 24 Jun 2014 13:14:54 +0700
parents 67990f8d8228
children 814398c7139b
line wrap: on
line diff
--- a/mod_muc_log/mod_muc_log.lua	Mon Jun 23 16:06:46 2014 -0400
+++ b/mod_muc_log/mod_muc_log.lua	Tue Jun 24 13:14:54 2014 +0700
@@ -16,21 +16,39 @@
 
 -- Module Definitions
 
+local function get_room_from_jid(jid)
+	local node, host = split_jid(jid);
+	local component = hosts[host];
+	if component then
+		local muc = component.modules.muc
+		if muc and rawget(muc,"rooms") then
+			-- We're running 0.9.x or 0.10 (old MUC API)
+			return muc.rooms[jid];
+		elseif muc and rawget(muc,"get_room_from_jid") then
+			-- We're running >0.10 (new MUC API)
+			return muc.get_room_from_jid(jid);
+		else
+			return
+		end
+	end
+end
+
 function log_if_needed(event)
 	local stanza = event.stanza;
 
-	if	(stanza.name == "presence") or
+	if (stanza.name == "presence") or
 		(stanza.name == "iq") or
-	   	(stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
+		(stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
 	then
 		local node, host = split_jid(stanza.attr.to);
-		local muc = hosts[host].muc;
 		if node and host then
 			local bare = node .. "@" .. host;
-			if muc and muc.rooms[bare] then
-				local room = muc.rooms[bare]
-				local today = os.date("%y%m%d");
-				local now = os.date("%X")
+			if get_room_from_jid(bare) then
+				local room = get_room_from_jid(bare)
+
+				local today = os.date("!%y%m%d");
+				local now = os.date("!%X")
+
 				local muc_to = nil
 				local muc_from = nil;
 				local already_joined = false;