Annotate

plugins/muc/persistent.lib.lua @ 7270:df22e314946c

MUC: Use already initialized logger
author Kim Alvefur <zash@zash.se>
date Fri, 11 Mar 2016 20:35:26 +0100
parent 6991:84e01dbb739e
child 7352:50b24b3476e6
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 if room.save then room:save(true); end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
19 return true;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
20 end
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
21
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
22 module:hook("muc-config-form", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
23 table.insert(event.form, {
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
24 name = "muc#roomconfig_persistentroom";
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
25 type = "boolean";
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
26 label = "Make Room Persistent?";
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 });
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
29 end);
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);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
43 end);
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 };