Software /
code /
prosody
Annotate
plugins/muc/persistent.lib.lua @ 8716:2f3b08ad9b8a
luacheckrc: Forget about _G.hosts, things should use _G.prosody.hosts
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 29 Mar 2018 16:42:24 +0200 |
parent | 7401:e16b3fd0bd80 |
child | 9014:326fedc1d3c6 |
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"; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
25 label = "Make Room Persistent?"; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
26 value = get_persistent(event.room); |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
27 }); |
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
|
28 end, 100-3); |
6222
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
29 |
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
|
30 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
|
31 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
|
32 event.status_codes["104"] = true; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
33 end |
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 |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
36 module:hook("muc-disco#info", function(event) |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
37 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
|
38 end); |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
39 |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
40 module:hook("muc-room-destroyed", function(event) |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
41 set_persistent(event.room, false); |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
42 end); |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
43 |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
44 return { |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
45 get = get_persistent; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
46 set = set_persistent; |
355b29881117
plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
47 }; |