Mercurial > prosody-hg
comparison plugins/muc/mod_muc.lua @ 9015:dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 11 Jul 2018 03:37:57 +0200 |
| parents | a54bcc76cd22 |
| children | 946ae1181c57 |
comparison
equal
deleted
inserted
replaced
| 9014:326fedc1d3c6 | 9015:dc606dc89f44 |
|---|---|
| 320 module:hook("muc-room-destroyed",function(event) | 320 module:hook("muc-room-destroyed",function(event) |
| 321 local room = event.room; | 321 local room = event.room; |
| 322 forget_room(room); | 322 forget_room(room); |
| 323 delete_room(room); | 323 delete_room(room); |
| 324 end); | 324 end); |
| 325 | |
| 326 if module:get_option_boolean("muc_tombstones", true) then | |
| 327 | |
| 328 local ttl = module:get_option_number("muc_tombstone_expiry", 86400 * 31); | |
| 329 | |
| 330 module:hook("muc-room-destroyed",function(event) | |
| 331 local room = event.room; | |
| 332 if not room:get_persistent() then return end | |
| 333 | |
| 334 local tombstone = new_room(room.jid, { | |
| 335 locked = os.time() + ttl; | |
| 336 destroyed = true; | |
| 337 reason = event.reason; | |
| 338 newjid = event.newjid; | |
| 339 -- password? | |
| 340 }); | |
| 341 tombstone.save = room_save; | |
| 342 tombstone:set_persistent(true); | |
| 343 tombstone:set_hidden(true); | |
| 344 tombstone:save(true); | |
| 345 return true; | |
| 346 end, -10); | |
| 347 end | |
| 325 | 348 |
| 326 do | 349 do |
| 327 local restrict_room_creation = module:get_option("restrict_room_creation"); | 350 local restrict_room_creation = module:get_option("restrict_room_creation"); |
| 328 if restrict_room_creation == true then | 351 if restrict_room_creation == true then |
| 329 restrict_room_creation = "admin"; | 352 restrict_room_creation = "admin"; |
| 370 } do | 393 } do |
| 371 module:hook(event_name, function (event) | 394 module:hook(event_name, function (event) |
| 372 local origin, stanza = event.origin, event.stanza; | 395 local origin, stanza = event.origin, event.stanza; |
| 373 local room_jid = jid_bare(stanza.attr.to); | 396 local room_jid = jid_bare(stanza.attr.to); |
| 374 local room = get_room_from_jid(room_jid); | 397 local room = get_room_from_jid(room_jid); |
| 398 | |
| 399 if room and room._data.destroyed then | |
| 400 if stanza.attr.type == nil and stanza.name == "presence" then | |
| 401 if room._data.locked < os.time() then | |
| 402 -- Allow the room to be recreated after time has passed | |
| 403 delete_room(room); | |
| 404 room = nil; | |
| 405 else | |
| 406 local reply = st.reply(stanza) | |
| 407 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | |
| 408 :tag("item", { affiliation='none', role='none' }):up() | |
| 409 :tag("destroy", {jid=room._data.newjid}):text(room._data.reason); | |
| 410 reply.attr.type = "unavailable"; | |
| 411 event.origin.send(reply); | |
| 412 return true; | |
| 413 end | |
| 414 end | |
| 415 end | |
| 416 | |
| 375 if room == nil then | 417 if room == nil then |
| 376 -- Watch presence to create rooms | 418 -- Watch presence to create rooms |
| 377 if stanza.attr.type == nil and stanza.name == "presence" then | 419 if stanza.attr.type == nil and stanza.name == "presence" then |
| 378 room = muclib.new_room(room_jid); | 420 room = muclib.new_room(room_jid); |
| 379 return room:handle_first_presence(origin, stanza); | 421 return room:handle_first_presence(origin, stanza); |
