util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / muc / persistent.lib.lua
blobc3b16ea453d48e2b3205de6dc60717f11760e67c
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_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;
15 end
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;
21 return true;
22 end
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
27 return;
28 end
29 table.insert(event.form, {
30 name = "muc#roomconfig_persistentroom";
31 type = "boolean";
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);
35 });
36 end, 100-5);
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
41 end
42 if set_persistent(event.room, 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_persistent(event.room) and "muc_persistent" or "muc_temporary"}):up();
49 end);
51 module:hook("muc-room-destroyed", function(event)
52 set_persistent(event.room, false);
53 end, -100);
55 return {
56 get = get_persistent;
57 set = set_persistent;