plugins/muc/mod_muc.lua

changeset 3330
bdc325ce9fbc
parent 3262
330010ef078f
child 3388
02e668d64e05
equal deleted inserted replaced
3329:9adafeeadecb 3330:bdc325ce9fbc
29 29
30 local rooms = {}; 30 local rooms = {};
31 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; 31 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
32 local component; 32 local component;
33 33
34 -- Configurable options
35 local max_history_messages = module:get_option_number("max_history_messages");
36
34 local function is_admin(jid) 37 local function is_admin(jid)
35 return um_is_admin(jid) or um_is_admin(jid, module.host); 38 return um_is_admin(jid) or um_is_admin(jid, module.host);
36 end 39 end
37 40
38 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end 41 local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end
56 end 59 end
57 60
58 for jid in pairs(persistent_rooms) do 61 for jid in pairs(persistent_rooms) do
59 local node = jid_split(jid); 62 local node = jid_split(jid);
60 local data = datamanager.load(node, muc_host, "config") or {}; 63 local data = datamanager.load(node, muc_host, "config") or {};
61 local room = muc_new_room(jid); 64 local room = muc_new_room(jid, {
65 history_length = max_history_messages;
66 });
62 room._data = data._data; 67 room._data = data._data;
68 room._data.history_length = max_history_messages; --TODO: Need to allow per-room with a global limit
63 room._affiliations = data._affiliations; 69 room._affiliations = data._affiliations;
64 room.route_stanza = room_route_stanza; 70 room.route_stanza = room_route_stanza;
65 room.save = room_save; 71 room.save = room_save;
66 rooms[jid] = room; 72 rooms[jid] = room;
67 end 73 end
68 74
69 local host_room = muc_new_room(muc_host); 75 local host_room = muc_new_room(muc_host, {
76 history_length = max_history_messages;
77 });
70 host_room.route_stanza = room_route_stanza; 78 host_room.route_stanza = room_route_stanza;
71 host_room.save = room_save; 79 host_room.save = room_save;
72 80
73 local function get_disco_info(stanza) 81 local function get_disco_info(stanza)
74 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") 82 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info")
111 local bare = to_node.."@"..to_host; 119 local bare = to_node.."@"..to_host;
112 if to_host == muc_host or bare == muc_host then 120 if to_host == muc_host or bare == muc_host then
113 local room = rooms[bare]; 121 local room = rooms[bare];
114 if not room then 122 if not room then
115 if not(restrict_room_creation) or is_admin(stanza.attr.from) then 123 if not(restrict_room_creation) or is_admin(stanza.attr.from) then
116 room = muc_new_room(bare); 124 room = muc_new_room(bare, {
125 history_length = max_history_messages;
126 });
117 room.route_stanza = room_route_stanza; 127 room.route_stanza = room_route_stanza;
118 room.save = room_save; 128 room.save = room_save;
119 rooms[bare] = room; 129 rooms[bare] = room;
120 end 130 end
121 end 131 end

mercurial