Diff

plugins/muc/mod_muc.lua @ 3330:bdc325ce9fbc

MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
author Matthew Wild <mwild1@gmail.com>
date Tue, 06 Jul 2010 17:09:23 +0100
parent 3262:330010ef078f
child 3388:02e668d64e05
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua	Mon Jul 05 12:17:09 2010 +0100
+++ b/plugins/muc/mod_muc.lua	Tue Jul 06 17:09:23 2010 +0100
@@ -31,6 +31,9 @@
 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
 local component;
 
+-- Configurable options
+local max_history_messages = module:get_option_number("max_history_messages");
+
 local function is_admin(jid)
 	return um_is_admin(jid) or um_is_admin(jid, module.host);
 end
@@ -58,15 +61,20 @@
 for jid in pairs(persistent_rooms) do
 	local node = jid_split(jid);
 	local data = datamanager.load(node, muc_host, "config") or {};
-	local room = muc_new_room(jid);
+	local room = muc_new_room(jid, {
+		history_length = max_history_messages;
+	});
 	room._data = data._data;
+	room._data.history_length = max_history_messages; --TODO: Need to allow per-room with a global limit
 	room._affiliations = data._affiliations;
 	room.route_stanza = room_route_stanza;
 	room.save = room_save;
 	rooms[jid] = room;
 end
 
-local host_room = muc_new_room(muc_host);
+local host_room = muc_new_room(muc_host, {
+	history_length = max_history_messages;
+});
 host_room.route_stanza = room_route_stanza;
 host_room.save = room_save;
 
@@ -113,7 +121,9 @@
 			local room = rooms[bare];
 			if not room then
 				if not(restrict_room_creation) or is_admin(stanza.attr.from) then
-					room = muc_new_room(bare);
+					room = muc_new_room(bare, {
+						history_length = max_history_messages;
+					});
 					room.route_stanza = room_route_stanza;
 					room.save = room_save;
 					rooms[bare] = room;