# HG changeset patch # User Kim Alvefur # Date 1413998969 -7200 # Node ID 915bdcb35e79d0adc723a29ae71c806fda9239de # Parent 71d85bc0dea85cc241efc1617ee48c86f38fcec2 mod_mam_muc: Restructure initialization diff -r 71d85bc0dea8 -r 915bdcb35e79 mod_mam_muc/mod_mam_muc.lua --- 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;