MUC: Assign priorities to config form hooks so they have a consistent order on each...
[prosody.git] / plugins / muc / hidden.lib.lua
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 --
9
10 local function get_hidden(room)
11         return room._data.hidden;
12 end
13
14 local function set_hidden(room, hidden)
15         hidden = hidden and true or nil;
16         if get_hidden(room) == hidden then return false; end
17         room._data.hidden = hidden;
18         return true;
19 end
20
21 module:hook("muc-config-form", function(event)
22         table.insert(event.form, {
23                 name = "muc#roomconfig_publicroom";
24                 type = "boolean";
25                 label = "Make Room Publicly Searchable?";
26                 value = not get_hidden(event.room);
27         });
28 end, 100-5);
29
30 module:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event)
31         if set_hidden(event.room, not event.value) then
32                 event.status_codes["104"] = true;
33         end
34 end);
35
36 module:hook("muc-disco#info", function(event)
37         event.reply:tag("feature", {var = get_hidden(event.room) and "muc_hidden" or "muc_public"}):up();
38 end);
39
40 return {
41         get = get_hidden;
42         set = set_hidden;
43 };