Software /
code /
prosody
Comparison
plugins/muc/lock.lib.lua @ 6242:67efeadd9e77
plugins/muc/lock.lib: lock inside of pre-create instead of 'created'
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 29 Apr 2014 18:50:30 -0400 |
parent | 6207:a5928fdeaf97 |
child | 6329:6b3eb1611587 |
comparison
equal
deleted
inserted
replaced
6241:6b4ff34dc8ea | 6242:67efeadd9e77 |
---|---|
21 local function is_locked(room) | 21 local function is_locked(room) |
22 return not not room.locked; | 22 return not not room.locked; |
23 end | 23 end |
24 | 24 |
25 if lock_rooms then | 25 if lock_rooms then |
26 module:hook("muc-room-created", function(event) | 26 module:hook("muc-room-pre-create", function(event) |
27 -- Older groupchat protocol doesn't lock | |
28 if not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then return end | |
29 -- Lock room at creation | |
27 local room = event.room; | 30 local room = event.room; |
28 lock(room); | 31 lock(room); |
29 if lock_room_timeout and lock_room_timeout > 0 then | 32 if lock_room_timeout and lock_room_timeout > 0 then |
30 module:add_timer(lock_room_timeout, function () | 33 module:add_timer(lock_room_timeout, function () |
31 if is_locked(room) then | 34 if is_locked(room) then |
32 room:destroy(); -- Not unlocked in time | 35 room:destroy(); -- Not unlocked in time |
33 end | 36 end |
34 end); | 37 end); |
35 end | 38 end |
36 end); | 39 end, 10); |
37 end | 40 end |
38 | |
39 -- Older groupchat protocol doesn't lock | |
40 module:hook("muc-room-pre-create", function(event) | |
41 if is_locked(event.room) and not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then | |
42 unlock(event.room); | |
43 end | |
44 end, 10); | |
45 | 41 |
46 -- Don't let users into room while it is locked | 42 -- Don't let users into room while it is locked |
47 module:hook("muc-occupant-pre-join", function(event) | 43 module:hook("muc-occupant-pre-join", function(event) |
48 if not event.is_new_room and is_locked(event.room) then -- Deny entry | 44 if not event.is_new_room and is_locked(event.room) then -- Deny entry |
49 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found")); | 45 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found")); |