util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / muc / moderated.lib.lua
blob64ddb5420a96d4db573c22f6c5761e2d9441ba66
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 function get_moderated(room)
11 return room._data.moderated;
12 end
14 local function set_moderated(room, moderated)
15 moderated = moderated and true or nil;
16 if get_moderated(room) == moderated then return false; end
17 room._data.moderated = moderated;
18 return true;
19 end
21 module:hook("muc-disco#info", function(event)
22 event.reply:tag("feature", {var = get_moderated(event.room) and "muc_moderated" or "muc_unmoderated"}):up();
23 end);
25 module:hook("muc-config-form", function(event)
26 table.insert(event.form, {
27 name = "muc#roomconfig_moderatedroom";
28 type = "boolean";
29 label = "Moderated (require permission to speak)";
30 desc = "In moderated rooms occupants must be given permission to speak by a room moderator";
31 value = get_moderated(event.room);
32 });
33 end, 80-3);
35 module:hook("muc-config-submitted/muc#roomconfig_moderatedroom", function(event)
36 if set_moderated(event.room, event.value) then
37 event.status_codes["104"] = true;
38 end
39 end);
41 module:hook("muc-get-default-role", function(event)
42 if event.affiliation == nil then
43 if get_moderated(event.room) then
44 -- XEP-0045:
45 -- An implementation MAY grant voice by default to visitors in unmoderated rooms.
46 return "visitor"
47 end
48 end
49 end, 1);
51 return {
52 get = get_moderated;
53 set = set_moderated;