comparison mod_mam_muc/mod_mam_muc.lua @ 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
comparison
equal deleted inserted replaced
1532:71d85bc0dea8 1533:915bdcb35e79
42 42
43 local rooms = hosts[module.host].modules.muc.rooms; 43 local rooms = hosts[module.host].modules.muc.rooms;
44 44
45 local send_history, save_to_history; 45 local send_history, save_to_history;
46 46
47 if log_all_rooms then
48 -- Override history methods for all rooms. 47 -- Override history methods for all rooms.
49 local _send_history = room_mt.send_history; 48 module:hook("muc-room-created", function (event)
50 local _save_to_history = room_mt.save_to_history; 49 local room = event.room;
51 function module.load() 50 if log_all_rooms or room._data.logging then
52 room_mt.send_history = send_history; 51 room.send_history = send_history;
53 room_mt.save_to_history = save_to_history; 52 room.save_to_history = save_to_history;
54 end 53 end
55 function module.unload() 54 end);
56 room_mt.send_history = _send_history; 55
57 room_mt.save_to_history = _save_to_history; 56 function module.load()
58 end 57 for _, room in pairs(rooms) do
59 else 58 if log_all_rooms or room._data.logging then
60 -- Only override histary on rooms with logging enabled 59 room.send_history = send_history;
61 function module.load() 60 room.save_to_history = save_to_history;
62 for _, room in pairs(rooms) do 61 end
63 if room._data.logging then 62 end
64 room.send_history = send_history; 63 end
65 room.save_to_history = save_to_history; 64 function module.unload()
66 end 65 for _, room in pairs(rooms) do
67 end 66 if room.send_history == send_history then
68 end 67 room.send_history = nil;
69 function module.unload() 68 room.save_to_history = nil;
70 for _, room in pairs(rooms) do 69 end
71 if room.send_history == send_history then 70 end
72 room.send_history = nil; 71 end
73 room.save_to_history = nil; 72
74 end 73 if not log_all_rooms then
75 end
76 end
77 module:hook("muc-config-form", function(event) 74 module:hook("muc-config-form", function(event)
78 local room, form = event.room, event.form; 75 local room, form = event.room, event.form;
79 local logging_enabled = room._data.logging; 76 local logging_enabled = room._data.logging;
80 if logging_enabled == nil then 77 if logging_enabled == nil then
81 logging_enabled = log_by_default; 78 logging_enabled = log_by_default;