Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 5195:ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Nov 2012 21:57:06 +0000 |
parent | 5074:a87afeea8b48 |
child | 5210:862a6fae05e7 |
comparison
equal
deleted
inserted
replaced
5192:3fc3a3072cc2 | 5195:ce5d7538ac48 |
---|---|
35 rooms = {}; | 35 rooms = {}; |
36 local rooms = rooms; | 36 local rooms = rooms; |
37 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; | 37 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; |
38 | 38 |
39 -- Configurable options | 39 -- Configurable options |
40 local max_history_messages = module:get_option_number("max_history_messages"); | 40 muclib.set_max_history_length(module:get_option_number("max_history_messages")); |
41 | 41 |
42 local function is_admin(jid) | 42 local function is_admin(jid) |
43 return um_is_admin(jid, module.host); | 43 return um_is_admin(jid, module.host); |
44 end | 44 end |
45 | 45 |
80 local persistent_errors = false; | 80 local persistent_errors = false; |
81 for jid in pairs(persistent_rooms) do | 81 for jid in pairs(persistent_rooms) do |
82 local node = jid_split(jid); | 82 local node = jid_split(jid); |
83 local data = datamanager.load(node, muc_host, "config"); | 83 local data = datamanager.load(node, muc_host, "config"); |
84 if data then | 84 if data then |
85 local room = muc_new_room(jid, { | 85 local room = muc_new_room(jid); |
86 max_history_length = max_history_messages; | |
87 }); | |
88 room._data = data._data; | 86 room._data = data._data; |
89 room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings | |
90 room._affiliations = data._affiliations; | 87 room._affiliations = data._affiliations; |
91 room.route_stanza = room_route_stanza; | 88 room.route_stanza = room_route_stanza; |
92 room.save = room_save; | 89 room.save = room_save; |
93 rooms[jid] = room; | 90 rooms[jid] = room; |
94 else -- missing room data | 91 else -- missing room data |
97 persistent_errors = true; | 94 persistent_errors = true; |
98 end | 95 end |
99 end | 96 end |
100 if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end | 97 if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end |
101 | 98 |
102 local host_room = muc_new_room(muc_host, { | 99 local host_room = muc_new_room(muc_host); |
103 max_history_length = max_history_messages; | |
104 }); | |
105 host_room.route_stanza = room_route_stanza; | 100 host_room.route_stanza = room_route_stanza; |
106 host_room.save = room_save; | 101 host_room.save = room_save; |
107 | 102 |
108 local function get_disco_info(stanza) | 103 local function get_disco_info(stanza) |
109 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") | 104 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
152 return true; | 147 return true; |
153 end | 148 end |
154 if not(restrict_room_creation) or | 149 if not(restrict_room_creation) or |
155 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or | 150 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or |
156 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then | 151 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then |
157 room = muc_new_room(bare, { | 152 room = muc_new_room(bare); |
158 max_history_length = max_history_messages; | |
159 }); | |
160 room.route_stanza = room_route_stanza; | 153 room.route_stanza = room_route_stanza; |
161 room.save = room_save; | 154 room.save = room_save; |
162 rooms[bare] = room; | 155 rooms[bare] = room; |
163 end | 156 end |
164 end | 157 end |