changeset 1533:915bdcb35e79

mod_mam_muc: Restructure initialization
author Kim Alvefur <zash@zash.se>
date Wed, 22 Oct 2014 19:29:29 +0200
parents 71d85bc0dea8
children 4dd6eebc8fbd
files mod_mam_muc/mod_mam_muc.lua
diffstat 1 files changed, 21 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam_muc/mod_mam_muc.lua	Mon Oct 20 16:15:24 2014 -0700
+++ b/mod_mam_muc/mod_mam_muc.lua	Wed Oct 22 19:29:29 2014 +0200
@@ -44,36 +44,33 @@
 
 local send_history, save_to_history;
 
-if log_all_rooms then
 	-- Override history methods for all rooms.
-	local _send_history = room_mt.send_history;
-	local _save_to_history = room_mt.save_to_history;
-	function module.load()
-		room_mt.send_history = send_history;
-		room_mt.save_to_history = save_to_history;
+module:hook("muc-room-created", function (event)
+	local room = event.room;
+	if log_all_rooms or room._data.logging then
+		room.send_history = send_history;
+		room.save_to_history = save_to_history;
 	end
-	function module.unload()
-		room_mt.send_history = _send_history;
-		room_mt.save_to_history = _save_to_history;
-	end
-else
-	-- Only override histary on rooms with logging enabled
-	function module.load()
-		for _, room in pairs(rooms) do
-			if room._data.logging then
-				room.send_history = send_history;
-				room.save_to_history = save_to_history;
-			end
+end);
+
+function module.load()
+	for _, room in pairs(rooms) do
+		if log_all_rooms or room._data.logging then
+			room.send_history = send_history;
+			room.save_to_history = save_to_history;
 		end
 	end
-	function module.unload()
-		for _, room in pairs(rooms) do
-			if room.send_history == send_history then
-				room.send_history = nil;
-				room.save_to_history = nil;
-			end
+end
+function module.unload()
+	for _, room in pairs(rooms) do
+		if room.send_history == send_history then
+			room.send_history = nil;
+			room.save_to_history = nil;
 		end
 	end
+end
+
+if not log_all_rooms then
 	module:hook("muc-config-form", function(event)
 		local room, form = event.room, event.form;
 		local logging_enabled = room._data.logging;