Comparison

mod_mam_muc/mod_mam_muc.lua @ 1314:cc9831033f5d

mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
author Kim Alvefur <zash@zash.se>
date Thu, 20 Feb 2014 20:37:26 +0100
parent 1313:440d7276ca62
child 1315:e8eebf281405
comparison
equal deleted inserted replaced
1313:440d7276ca62 1314:cc9831033f5d
40 return 40 return
41 end 41 end
42 42
43 local rooms = hosts[module.host].modules.muc.rooms; 43 local rooms = hosts[module.host].modules.muc.rooms;
44 44
45 if not log_all_rooms then 45 local send_history, save_to_history;
46
47 if log_all_rooms then
48 -- Override history methods for all rooms.
49 local _send_history = room_mt.send_history;
50 local _save_to_history = room_mt.save_to_history;
51 function module.load()
52 room_mt.send_history = send_history;
53 room_mt.save_to_history = save_to_history;
54 end
55 function module.unload()
56 room_mt.send_history = _send_history;
57 room_mt.save_to_history = _save_to_history;
58 end
59 else
60 -- Only override histary on rooms with logging enabled
61 function module.load()
62 for _, room in pairs(rooms) do
63 if room._data.logging then
64 room.send_history = send_history;
65 room.save_to_history = save_to_history;
66 end
67 end
68 end
69 function module.unload()
70 for _, room in pairs(rooms) do
71 if room.send_history == send_history then
72 room.send_history = nil;
73 room.save_to_history = nil;
74 end
75 end
76 end
46 module:hook("muc-config-form", function(event) 77 module:hook("muc-config-form", function(event)
47 local room, form = event.room, event.form; 78 local room, form = event.room, event.form;
48 local logging_enabled = room._data.logging; 79 local logging_enabled = room._data.logging;
49 if logging_enabled == nil then 80 if logging_enabled == nil then
50 logging_enabled = log_by_default; 81 logging_enabled = log_by_default;
66 room._data.logging = new; 97 room._data.logging = new;
67 if type(changed) == "table" then 98 if type(changed) == "table" then
68 changed[muc_form_enable_logging] = true; 99 changed[muc_form_enable_logging] = true;
69 else 100 else
70 event.changed = true; 101 event.changed = true;
102 end
103 if new then
104 room.send_history = send_history;
105 room.save_to_history = save_to_history;
106 else
107 room.send_history = nil;
108 room.save_to_history = nil;
71 end 109 end
72 end 110 end
73 end); 111 end);
74 end 112 end
75 113