2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2014 Daurnimator
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
10 local restrict_persistent
= not module
:get_option_boolean("muc_room_allow_persistent", true);
11 local um_is_admin
= require
"core.usermanager".is_admin
;
13 local function get_persistent(room
)
14 return room
._data
.persistent
;
17 local function set_persistent(room
, persistent
)
18 persistent
= persistent
and true or nil;
19 if get_persistent(room
) == persistent
then return false; end
20 room
._data
.persistent
= persistent
;
24 module
:hook("muc-config-form", function(event
)
25 if restrict_persistent
and not um_is_admin(event
.actor
, module
.host
) then
26 -- Don't show option if hidden rooms are restricted and user is not admin of this host
29 table.insert(event
.form
, {
30 name
= "muc#roomconfig_persistentroom";
32 label
= "Persistent (room should remain even when it is empty)";
33 desc
= "Rooms are automatically deleted when they are empty, unless this option is enabled";
34 value
= get_persistent(event
.room
);
38 module
:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event
)
39 if restrict_persistent
and not um_is_admin(event
.actor
, module
.host
) then
40 return; -- Not allowed
42 if set_persistent(event
.room
, event
.value
) then
43 event
.status_codes
["104"] = true;
47 module
:hook("muc-disco#info", function(event
)
48 event
.reply
:tag("feature", {var
= get_persistent(event
.room
) and "muc_persistent" or "muc_temporary"}):up();
51 module
:hook("muc-room-destroyed", function(event
)
52 set_persistent(event
.room
, false);