Changeset

1104:34c86e4d6c9d

mod_muc_log: Add a room config option for logging
author Kim Alvefur <zash@zash.se>
date Wed, 10 Jul 2013 12:41:32 +0200
parents 1103:59657e03c25c
children 1105:7837a5f7c10d
files mod_muc_log/mod_muc_log.lua
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log/mod_muc_log.lua	Tue Jul 09 09:38:10 2013 +0200
+++ b/mod_muc_log/mod_muc_log.lua	Wed Jul 10 12:41:32 2013 +0200
@@ -8,6 +8,7 @@
 local datastore = "muc_log";
 local error_reply = require "util.stanza".error_reply;
 local storagemanager = storagemanager;
+local muc_form_config_option = "muc#roomconfig_enablelogging"
 
 local mod_host = module:get_host();
 local log_presences = module:get_option_boolean("muc_log_presences", false);
@@ -117,6 +118,31 @@
 	end
 end
 
+module:hook("muc-config-form", function(event)
+	local room, form = event.room, event.form;
+	table.insert(form,
+	{
+		name = muc_form_config_option,
+		type = "boolean",
+		label = "Enable Logging?",
+		value = room._data.logging or false,
+	}
+	);
+end);
+
+module:hook("muc-config-submitted", function(event)
+	local room, fields, changed = event.room, event.fields, event.changed;
+	local new = fields[muc_form_config_option];
+	if new ~= room._data.logging then
+		room._data.logging = new;
+		if type(changed) == "table" then
+			changed[muc_form_config_option] = true;
+		else
+			event.changed = true;
+		end
+	end
+end);
+
 module:hook("message/bare", log_if_needed, 1);
 if log_presences then
 	module:hook("iq/bare", log_if_needed, 1);