diff mod_mam_muc/mod_mam_muc.lua @ 1551:5127f4db9d39

mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
author Kim Alvefur <zash@zash.se>
date Sat, 08 Nov 2014 16:41:31 +0100
parents d3c847070618
children eed7db9f3157
line wrap: on
line diff
--- a/mod_mam_muc/mod_mam_muc.lua	Sat Nov 08 15:54:49 2014 +0100
+++ b/mod_mam_muc/mod_mam_muc.lua	Sat Nov 08 16:41:31 2014 +0100
@@ -13,14 +13,21 @@
 local jid_bare = require "util.jid".bare;
 local jid_split = require "util.jid".split;
 local dataform = require "util.dataforms".new;
+local it = require"util.iterators";
 
+-- Support both old and new MUC code
 local mod_muc = module:depends"muc";
 local room_mt = mod_muc.room_mt;
 local rooms = rawget(mod_muc, "rooms");
+local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end;
 local new_muc = not rooms;
 if new_muc then
 	rooms = module:shared"muc/rooms";
 end
+local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
+	function (jid)
+		return rooms[jid];
+	end
 
 local getmetatable = getmetatable;
 local function is_stanza(x)
@@ -71,7 +78,7 @@
 	end);
 
 	function module.load()
-		for _, room in pairs(rooms) do
+		for room in each_room() do
 			if logging_enabled(room) then
 				room.send_history = send_history;
 				room.save_to_history = save_to_history;
@@ -79,7 +86,7 @@
 		end
 	end
 	function module.unload()
-		for _, room in pairs(rooms) do
+		for room in each_room() do
 			if room.send_history == send_history then
 				room.send_history = nil;
 				room.save_to_history = nil;
@@ -144,7 +151,7 @@
 	local orig_from = stanza.attr.from;
 	local query = stanza.tags[1];
 
-	local room_obj = rooms[room];
+	local room_obj = get_room_from_jid(room);
 	if not room_obj then
 		return origin.send(st.error_reply(stanza, "cancel", "item-not-found"))
 	end