Annotate

plugins/muc/persistent.lib.lua @ 6278:fcc3ef191293

plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
author daurnimator <quae@daurnimator.com>
date Tue, 17 Jun 2014 15:27:00 -0400
parent 6222:355b29881117
child 6991:84e01dbb739e
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
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
31 module:hook("muc-config-submitted", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
32 local new = event.fields["muc#roomconfig_persistentroom"];
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
33 if new ~= nil and set_persistent(event.room, new) then
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
34 event.status_codes["104"] = true;
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 end);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
37
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
38 module:hook("muc-disco#info", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
39 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
40 end);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
41
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
42 module:hook("muc-room-destroyed", function(event)
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
43 set_persistent(event.room, false);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
44 end);
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
45
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
46 return {
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
47 get = get_persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
48 set = set_persistent;
355b29881117 plugins/muc: Move persistent room configuration to own module
daurnimator <quae@daurnimator.com>
parents:
diff changeset
49 };