Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 5210:862a6fae05e7
MUC: Expose create_room(jid).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 08:57:58 +0500 |
parent | 5195:ce5d7538ac48 |
child | 5335:bb81c13d2c6f |
comparison
equal
deleted
inserted
replaced
5209:f5d121846d53 | 5210:862a6fae05e7 |
---|---|
75 end | 75 end |
76 end | 76 end |
77 if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end | 77 if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end |
78 end | 78 end |
79 | 79 |
80 function create_room(jid) | |
81 local room = muc_new_room(jid); | |
82 room.route_stanza = room_route_stanza; | |
83 room.save = room_save; | |
84 rooms[jid] = room; | |
85 return room; | |
86 end | |
87 | |
80 local persistent_errors = false; | 88 local persistent_errors = false; |
81 for jid in pairs(persistent_rooms) do | 89 for jid in pairs(persistent_rooms) do |
82 local node = jid_split(jid); | 90 local node = jid_split(jid); |
83 local data = datamanager.load(node, muc_host, "config"); | 91 local data = datamanager.load(node, muc_host, "config"); |
84 if data then | 92 if data then |
85 local room = muc_new_room(jid); | 93 local room = create_room(jid); |
86 room._data = data._data; | 94 room._data = data._data; |
87 room._affiliations = data._affiliations; | 95 room._affiliations = data._affiliations; |
88 room.route_stanza = room_route_stanza; | |
89 room.save = room_save; | |
90 rooms[jid] = room; | |
91 else -- missing room data | 96 else -- missing room data |
92 persistent_rooms[jid] = nil; | 97 persistent_rooms[jid] = nil; |
93 module:log("error", "Missing data for room '%s', removing from persistent room list", jid); | 98 module:log("error", "Missing data for room '%s', removing from persistent room list", jid); |
94 persistent_errors = true; | 99 persistent_errors = true; |
95 end | 100 end |
147 return true; | 152 return true; |
148 end | 153 end |
149 if not(restrict_room_creation) or | 154 if not(restrict_room_creation) or |
150 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or | 155 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or |
151 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then | 156 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then |
152 room = muc_new_room(bare); | 157 room = create_room(bare); |
153 room.route_stanza = room_route_stanza; | |
154 room.save = room_save; | |
155 rooms[bare] = room; | |
156 end | 158 end |
157 end | 159 end |
158 if room then | 160 if room then |
159 room:handle_stanza(origin, stanza); | 161 room:handle_stanza(origin, stanza); |
160 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room | 162 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room |
188 saved = true; | 190 saved = true; |
189 return {rooms = rooms}; | 191 return {rooms = rooms}; |
190 end | 192 end |
191 module.restore = function(data) | 193 module.restore = function(data) |
192 for jid, oldroom in pairs(data.rooms or {}) do | 194 for jid, oldroom in pairs(data.rooms or {}) do |
193 local room = muc_new_room(jid); | 195 local room = create_room(jid); |
194 room._jid_nick = oldroom._jid_nick; | 196 room._jid_nick = oldroom._jid_nick; |
195 room._occupants = oldroom._occupants; | 197 room._occupants = oldroom._occupants; |
196 room._data = oldroom._data; | 198 room._data = oldroom._data; |
197 room._affiliations = oldroom._affiliations; | 199 room._affiliations = oldroom._affiliations; |
198 room.route_stanza = room_route_stanza; | |
199 room.save = room_save; | |
200 rooms[jid] = room; | |
201 end | 200 end |
202 hosts[module:get_host()].muc = { rooms = rooms }; | 201 hosts[module:get_host()].muc = { rooms = rooms }; |
203 end | 202 end |
204 | 203 |
205 function shutdown_room(room, stanza) | 204 function shutdown_room(room, stanza) |