# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1373452892 -7200
# Node ID 34c86e4d6c9d5794544f7a4bb494967234598403
# Parent  59657e03c25c5ed397ef071a75c1c14c3ad01e81
mod_muc_log: Add a room config option for logging

diff -r 59657e03c25c -r 34c86e4d6c9d mod_muc_log/mod_muc_log.lua
--- 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);