Mercurial > prosody-hg
comparison plugins/muc/mod_muc.lua @ 6233:f400a4cdf352
Merge with daurnimator
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 17 May 2014 18:17:34 +0100 |
| parents | 355b29881117 |
| children | cc8a6ca2d7c5 |
comparison
equal
deleted
inserted
replaced
| 6178:e12b13a46878 | 6233:f400a4cdf352 |
|---|---|
| 21 restrict_room_creation = "admin"; | 21 restrict_room_creation = "admin"; |
| 22 elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then | 22 elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then |
| 23 restrict_room_creation = nil; | 23 restrict_room_creation = nil; |
| 24 end | 24 end |
| 25 end | 25 end |
| 26 local lock_rooms = module:get_option_boolean("muc_room_locking", false); | |
| 27 local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300); | |
| 28 | 26 |
| 29 local muclib = module:require "muc"; | 27 local muclib = module:require "muc"; |
| 30 local muc_new_room = muclib.new_room; | 28 local muc_new_room = muclib.new_room; |
| 29 local persistent = module:require "muc/persistent"; | |
| 31 local jid_split = require "util.jid".split; | 30 local jid_split = require "util.jid".split; |
| 32 local jid_bare = require "util.jid".bare; | 31 local jid_bare = require "util.jid".bare; |
| 33 local st = require "util.stanza"; | 32 local st = require "util.stanza"; |
| 34 local um_is_admin = require "core.usermanager".is_admin; | 33 local um_is_admin = require "core.usermanager".is_admin; |
| 35 local hosts = prosody.hosts; | 34 local hosts = prosody.hosts; |
| 45 | 44 |
| 46 module:depends("disco"); | 45 module:depends("disco"); |
| 47 module:add_identity("conference", "text", muc_name); | 46 module:add_identity("conference", "text", muc_name); |
| 48 module:add_feature("http://jabber.org/protocol/muc"); | 47 module:add_feature("http://jabber.org/protocol/muc"); |
| 49 module:depends "muc_unique" | 48 module:depends "muc_unique" |
| 49 module:require "muc/lock"; | |
| 50 | 50 |
| 51 local function is_admin(jid) | 51 local function is_admin(jid) |
| 52 return um_is_admin(jid, module.host); | 52 return um_is_admin(jid, module.host); |
| 53 end | 53 end |
| 54 | 54 |
| 64 return _set_affiliation(self, actor, jid, affiliation, callback, reason); | 64 return _set_affiliation(self, actor, jid, affiliation, callback, reason); |
| 65 end | 65 end |
| 66 | 66 |
| 67 local function room_save(room, forced) | 67 local function room_save(room, forced) |
| 68 local node = jid_split(room.jid); | 68 local node = jid_split(room.jid); |
| 69 persistent_rooms[room.jid] = room._data.persistent; | 69 local is_persistent = persistent.get(room); |
| 70 if room._data.persistent then | 70 persistent_rooms[room.jid] = is_persistent; |
| 71 if is_persistent then | |
| 71 local history = room._data.history; | 72 local history = room._data.history; |
| 72 room._data.history = nil; | 73 room._data.history = nil; |
| 73 local data = { | 74 local data = { |
| 74 jid = room.jid; | 75 jid = room.jid; |
| 75 _data = room._data; | 76 _data = room._data; |
| 88 | 89 |
| 89 function create_room(jid) | 90 function create_room(jid) |
| 90 local room = muc_new_room(jid); | 91 local room = muc_new_room(jid); |
| 91 room.save = room_save; | 92 room.save = room_save; |
| 92 rooms[jid] = room; | 93 rooms[jid] = room; |
| 93 if lock_rooms then | |
| 94 room:lock(); | |
| 95 if lock_room_timeout and lock_room_timeout > 0 then | |
| 96 module:add_timer(lock_room_timeout, function () | |
| 97 if room:is_locked() then | |
| 98 room:destroy(); -- Not unlocked in time | |
| 99 end | |
| 100 end); | |
| 101 end | |
| 102 end | |
| 103 module:fire_event("muc-room-created", { room = room }); | 94 module:fire_event("muc-room-created", { room = room }); |
| 104 return room; | 95 return room; |
| 105 end | 96 end |
| 106 | 97 |
| 107 function forget_room(jid) | 98 function forget_room(jid) |
| 147 forget_room(room.jid) | 138 forget_room(room.jid) |
| 148 end) | 139 end) |
| 149 | 140 |
| 150 module:hook("muc-occupant-left",function(event) | 141 module:hook("muc-occupant-left",function(event) |
| 151 local room = event.room | 142 local room = event.room |
| 152 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room | 143 if not next(room._occupants) and not persistent.get(room) then -- empty, non-persistent room |
| 153 module:fire_event("muc-room-destroyed", { room = room }); | 144 module:fire_event("muc-room-destroyed", { room = room }); |
| 154 end | 145 end |
| 155 end); | 146 end); |
| 156 | 147 |
| 157 -- Watch presence to create rooms | 148 -- Watch presence to create rooms |
| 226 room._affiliations = oldroom._affiliations; | 217 room._affiliations = oldroom._affiliations; |
| 227 end | 218 end |
| 228 hosts[module:get_host()].muc = { rooms = rooms }; | 219 hosts[module:get_host()].muc = { rooms = rooms }; |
| 229 end | 220 end |
| 230 | 221 |
| 231 function shutdown_room(room, stanza) | |
| 232 for nick, occupant in pairs(room._occupants) do | |
| 233 stanza.attr.from = nick; | |
| 234 for jid in pairs(occupant.sessions) do | |
| 235 stanza.attr.to = jid; | |
| 236 room:_route_stanza(stanza); | |
| 237 room._jid_nick[jid] = nil; | |
| 238 end | |
| 239 room._occupants[nick] = nil; | |
| 240 end | |
| 241 end | |
| 242 function shutdown_component() | 222 function shutdown_component() |
| 243 if not saved then | 223 if not saved then |
| 244 local stanza = st.presence({type = "unavailable"}) | 224 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
| 245 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | |
| 246 :tag("item", { affiliation='none', role='none' }):up() | |
| 247 :tag("status", { code = "332"}):up(); | 225 :tag("status", { code = "332"}):up(); |
| 248 for roomjid, room in pairs(rooms) do | 226 for roomjid, room in pairs(rooms) do |
| 249 shutdown_room(room, stanza); | 227 room:clear(x); |
| 250 end | 228 end |
| 251 shutdown_room(host_room, stanza); | 229 host_room:clear(x); |
| 252 end | 230 end |
| 253 end | 231 end |
| 254 module.unload = shutdown_component; | 232 module.unload = shutdown_component; |
| 255 module:hook_global("server-stopping", shutdown_component); | 233 module:hook_global("server-stopping", shutdown_component); |
| 256 | 234 |
