Annotate

plugins/muc/persistent.lib.lua @ 9034:1c709e3d2e5e

MUC: Improve labels of all config form items
author Matthew Wild <mwild1@gmail.com>
date Fri, 13 Jul 2018 13:22:40 +0100
parent 9014:326fedc1d3c6
child 9035:173c0e16e704
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6222
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
1 -- Prosody IM
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
4 -- Copyright (C) 2014 Daurnimator
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
5 --
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
8 --
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
9
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
10 local function get_persistent(room)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
11 return room._data.persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
12 end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
13
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
14 local function set_persistent(room, persistent)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
15 persistent = persistent and true or nil;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
16 if get_persistent(room) == persistent then return false; end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
17 room._data.persistent = persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
18 return true;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
19 end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
20
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
21 module:hook("muc-config-form", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
22 table.insert(event.form, {
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
23 name = "muc#roomconfig_persistentroom";
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
24 type = "boolean";
9034
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 9014
diff changeset
25 label = "Persistent (room should remain even when it is empty)";
1c709e3d2e5e MUC: Improve labels of all config form items
Matthew Wild <mwild1@gmail.com>
parents: 9014
diff changeset
26 desc = "Rooms are automatically deleted when they are empty, unless this option is enabled";
6222
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
27 value = get_persistent(event.room);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
28 });
7401
e16b3fd0bd80 MUC: Assign priorities to config form hooks so they have a consistent order on each start
Kim Alvefur <zash@zash.se>
parents: 7353
diff changeset
29 end, 100-3);
6222
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
30
6991
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6222
diff changeset
31 module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event)
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6222
diff changeset
32 if set_persistent(event.room, event.value) then
6222
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
33 event.status_codes["104"] = true;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
34 end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
35 end);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
36
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
37 module:hook("muc-disco#info", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
38 event.reply:tag("feature", {var = get_persistent(event.room) and "muc_persistent" or "muc_temporary"}):up();
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
39 end);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
40
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
41 module:hook("muc-room-destroyed", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
42 set_persistent(event.room, false);
9014
326fedc1d3c6 MUC: Unset persistence of destroyed rooms later in event chain
Kim Alvefur <zash@zash.se>
parents: 7401
diff changeset
43 end, -100);
6222
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
44
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
45 return {
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
46 get = get_persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
47 set = set_persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
48 };