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_public
= not module
:get_option_boolean("muc_room_allow_public", true);
11 local um_is_admin
= require
"core.usermanager".is_admin
;
13 local function get_hidden(room
)
14 return room
._data
.hidden
;
17 local function set_hidden(room
, hidden
)
18 hidden
= hidden
and true or nil;
19 if get_hidden(room
) == hidden
then return false; end
20 room
._data
.hidden
= hidden
;
24 module
:hook("muc-config-form", function(event
)
25 if restrict_public
and not um_is_admin(event
.actor
, module
.host
) then
26 -- Don't show option if public rooms are restricted and user is not admin of this host
29 table.insert(event
.form
, {
30 name
= "muc#roomconfig_publicroom";
32 label
= "Include room information in public lists";
33 desc
= "Enable this to allow people to find the room";
34 value
= not get_hidden(event
.room
);
38 module
:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event
)
39 if restrict_public
and not um_is_admin(event
.actor
, module
.host
) then
40 return; -- Not allowed
42 if set_hidden(event
.room
, not event
.value
) then
43 event
.status_codes
["104"] = true;
47 module
:hook("muc-disco#info", function(event
)
48 event
.reply
:tag("feature", {var
= get_hidden(event
.room
) and "muc_hidden" or "muc_public"}):up();