util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / muc / lock.lib.lua
blob062ab615e3990495e4e85063e1e146c420afb1e4
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2014 Daurnimator
5 --
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
8 --
10 local st = require "util.stanza";
12 local lock_rooms = module:get_option_boolean("muc_room_locking", true);
13 local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300);
15 local function lock(room)
16 module:fire_event("muc-room-locked", {room = room;});
17 room._data.locked = os.time() + lock_room_timeout;
18 end
19 local function unlock(room)
20 module:fire_event("muc-room-unlocked", {room = room;});
21 room._data.locked = nil;
22 end
23 local function is_locked(room)
24 local ts = room._data.locked;
25 if ts then
26 if os.time() < ts then return true; end
27 unlock(room);
28 end
29 return false;
30 end
32 if lock_rooms then
33 module:hook("muc-room-pre-create", function(event)
34 -- Older groupchat protocol doesn't lock
35 if not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then return end
36 -- Lock room at creation
37 local room = event.room;
38 lock(room);
39 end, 10);
40 end
42 -- Don't let users into room while it is locked
43 module:hook("muc-occupant-pre-join", function(event)
44 if not event.is_new_room and is_locked(event.room) then -- Deny entry
45 module:log("debug", "Room is locked, denying entry");
46 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found"));
47 return true;
48 end
49 end, -30);
51 -- When config is submitted; unlock the room
52 module:hook("muc-config-submitted", function(event)
53 if is_locked(event.room) then
54 unlock(event.room);
55 end
56 end, -1);
58 return {
59 lock = lock;
60 unlock = unlock;
61 is_locked = is_locked;