mod_csi_simple: Consider messages encrypted payload as important (fixes part of ...
[prosody.git] / plugins / muc / hidden.lib.lua
blob153df21a7386b4eb52abdab2495d763ecb71c6d6
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 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;
15 end
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;
21 return true;
22 end
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
27 return;
28 end
29 table.insert(event.form, {
30 name = "muc#roomconfig_publicroom";
31 type = "boolean";
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);
35 });
36 end, 100-9);
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
41 end
42 if set_hidden(event.room, not event.value) then
43 event.status_codes["104"] = true;
44 end
45 end);
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();
49 end);
51 return {
52 get = get_hidden;
53 set = set_hidden;