Software /
code /
prosody
Annotate
plugins/muc/mod_muc.lua @ 6211:a4d26656df04
plugins/muc/muc.lib: Clean up whois handling
- adds functions `can_see_real_jids` and `get_base_presence`
- In `publicise_occupant_status`, we don't generate each type of presence until it's used
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Thu, 03 Apr 2014 12:25:03 -0400 |
parent | 6206:f937bb5c83c3 |
child | 6222:355b29881117 |
rev | line source |
---|---|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2033
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2033
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5692
diff
changeset
|
4 -- |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 -- |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
5807
d7212bd61b60
mod_muc: Import util.array
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
9 local array = require "util.array"; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 if module:get_host_type() ~= "component" then |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 end |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local muc_host = module:get_host(); |
2028
4f33100195a0
MUC: Added 'name' config option, for specifying the component's name in disco responses.
Waqas Hussain <waqas20@gmail.com>
parents:
1781
diff
changeset
|
16 local muc_name = module:get_option("name"); |
4f33100195a0
MUC: Added 'name' config option, for specifying the component's name in disco responses.
Waqas Hussain <waqas20@gmail.com>
parents:
1781
diff
changeset
|
17 if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
18 local restrict_room_creation = module:get_option("restrict_room_creation"); |
3575
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
19 if restrict_room_creation then |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5692
diff
changeset
|
20 if restrict_room_creation == true then |
3575
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
21 restrict_room_creation = "admin"; |
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
22 elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then |
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
23 restrict_room_creation = nil; |
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
24 end |
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
25 end |
5808
026367992a0f
mod_muc: Support for locking newly-created rooms until they are configured (enabled with muc_room_locking = true)
Matthew Wild <mwild1@gmail.com>
parents:
5807
diff
changeset
|
26 |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
27 local muclib = module:require "muc"; |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
28 local muc_new_room = muclib.new_room; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local jid_split = require "util.jid".split; |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
30 local jid_bare = require "util.jid".bare; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 local st = require "util.stanza"; |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
32 local um_is_admin = require "core.usermanager".is_admin; |
5376
ba9be0be4bbb
MUC: Access prosody.hosts instead of the old global hosts
Kim Alvefur <zash@zash.se>
parents:
5335
diff
changeset
|
33 local hosts = prosody.hosts; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 |
3576
8d8ce17b83ca
MUC: Expose the rooms table as a global 'rooms'.
Waqas Hussain <waqas20@gmail.com>
parents:
3575
diff
changeset
|
35 rooms = {}; |
8d8ce17b83ca
MUC: Expose the rooms table as a global 'rooms'.
Waqas Hussain <waqas20@gmail.com>
parents:
3575
diff
changeset
|
36 local rooms = rooms; |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
37 local persistent_rooms_storage = module:open_store("persistent"); |
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
38 local persistent_rooms = persistent_rooms_storage:get() or {}; |
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
39 local room_configs = module:open_store("config"); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
40 |
3330
bdc325ce9fbc
MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents:
3262
diff
changeset
|
41 -- Configurable options |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5074
diff
changeset
|
42 muclib.set_max_history_length(module:get_option_number("max_history_messages")); |
3330
bdc325ce9fbc
MUC: Make number of stored history messages configurable with option max_history_messages (thanks michal and others who requested)
Matthew Wild <mwild1@gmail.com>
parents:
3262
diff
changeset
|
43 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
44 module:depends("disco"); |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
45 module:add_identity("conference", "text", muc_name); |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
46 module:add_feature("http://jabber.org/protocol/muc"); |
6091
3a1c39b31497
plugins/muc/mod_muc: Move Xep-0307 MUC unique to seperate file
daurnimator <quae@daurnimator.com>
parents:
6000
diff
changeset
|
47 module:depends "muc_unique" |
6206
f937bb5c83c3
plugins/muc: Move locking to seperate module
daurnimator <quae@daurnimator.com>
parents:
6205
diff
changeset
|
48 module:require "muc/lock"; |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
49 |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
50 local function is_admin(jid) |
3388
02e668d64e05
MUC: No need to call is_admin twice now, global admins are admins on hosts
Matthew Wild <mwild1@gmail.com>
parents:
3330
diff
changeset
|
51 return um_is_admin(jid, module.host); |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
52 end |
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
53 |
5984
c68e2b11d691
MUC: Expose room metatable on module
Kim Alvefur <zash@zash.se>
parents:
5945
diff
changeset
|
54 room_mt = muclib.room_mt; -- Yes, global. |
c68e2b11d691
MUC: Expose room metatable on module
Kim Alvefur <zash@zash.se>
parents:
5945
diff
changeset
|
55 local _set_affiliation = room_mt.set_affiliation; |
c68e2b11d691
MUC: Expose room metatable on module
Kim Alvefur <zash@zash.se>
parents:
5945
diff
changeset
|
56 local _get_affiliation = room_mt.get_affiliation; |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
57 function muclib.room_mt:get_affiliation(jid) |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
58 if is_admin(jid) then return "owner"; end |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
59 return _get_affiliation(self, jid); |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
60 end |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
61 function muclib.room_mt:set_affiliation(actor, jid, affiliation, callback, reason) |
5074
a87afeea8b48
mod_muc: Fix syntax error (thanks Florob)
Matthew Wild <mwild1@gmail.com>
parents:
5064
diff
changeset
|
62 if is_admin(jid) then return nil, "modify", "not-acceptable"; end |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
63 return _set_affiliation(self, actor, jid, affiliation, callback, reason); |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
64 end |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
65 |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
66 local function room_save(room, forced) |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
67 local node = jid_split(room.jid); |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
68 persistent_rooms[room.jid] = room._data.persistent; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
69 if room._data.persistent then |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
70 local history = room._data.history; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
71 room._data.history = nil; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
72 local data = { |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
73 jid = room.jid; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
74 _data = room._data; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
75 _affiliations = room._affiliations; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
76 }; |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
77 room_configs:set(node, data); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
78 room._data.history = history; |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
79 elseif forced then |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
80 room_configs:set(node, nil); |
4260
403aba5e49d5
mod_muc: Remove room from memory when it is made non-persistent and is empty
Matthew Wild <mwild1@gmail.com>
parents:
3675
diff
changeset
|
81 if not next(room._occupants) then -- Room empty |
403aba5e49d5
mod_muc: Remove room from memory when it is made non-persistent and is empty
Matthew Wild <mwild1@gmail.com>
parents:
3675
diff
changeset
|
82 rooms[room.jid] = nil; |
403aba5e49d5
mod_muc: Remove room from memory when it is made non-persistent and is empty
Matthew Wild <mwild1@gmail.com>
parents:
3675
diff
changeset
|
83 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
84 end |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
85 if forced then persistent_rooms_storage:set(nil, persistent_rooms); end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
86 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
87 |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
88 function create_room(jid) |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
89 local room = muc_new_room(jid); |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
90 room.save = room_save; |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
91 rooms[jid] = room; |
6205
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
92 module:fire_event("muc-room-created", { room = room }); |
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
93 return room; |
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
94 end |
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
95 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
96 function forget_room(jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
97 rooms[jid] = nil; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
98 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
99 |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
100 function get_room_from_jid(room_jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
101 return rooms[room_jid] |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
102 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
103 |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
104 local persistent_errors = false; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
105 for jid in pairs(persistent_rooms) do |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
106 local node = jid_split(jid); |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
107 local data = room_configs:get(node); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
108 if data then |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
109 local room = create_room(jid); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
110 room._data = data._data; |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
111 room._affiliations = data._affiliations; |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
112 else -- missing room data |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
113 persistent_rooms[jid] = nil; |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
114 module:log("error", "Missing data for room '%s', removing from persistent room list", jid); |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
115 persistent_errors = true; |
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
116 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
117 end |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
118 if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
119 |
5195
ce5d7538ac48
muc: Make max_history_messages simply a service-wide config option, and don't store it per-room (rooms still have their own history_message, but this is a global limit)
Matthew Wild <mwild1@gmail.com>
parents:
5074
diff
changeset
|
120 local host_room = muc_new_room(muc_host); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
121 host_room.save = room_save; |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
122 rooms[muc_host] = host_room; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
124 module:hook("host-disco-items", function(event) |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
125 local reply = event.reply; |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
126 module:log("debug", "host-disco-items called"); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 for jid, room in pairs(rooms) do |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
128 if not room:get_hidden() then |
3510
711eb5bf94b4
MUC: Make the room node be the default room name (thanks Zash).
Waqas Hussain <waqas20@gmail.com>
parents:
3388
diff
changeset
|
129 reply:tag("item", {jid=jid, name=room:get_name()}):up(); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
130 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 end |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
132 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
134 module:hook("muc-room-destroyed",function(event) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
135 local room = event.room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
136 forget_room(room.jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
137 end) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
138 |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
139 module:hook("muc-occupant-left",function(event) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
140 local room = event.room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
141 if not next(room._occupants) and not persistent_rooms[room.jid] then -- empty, non-persistent room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
142 module:fire_event("muc-room-destroyed", { room = room }); |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
143 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
144 end); |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
145 |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
146 -- Watch presence to create rooms |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
147 local function attempt_room_creation(event) |
3560
fb49b63e3fe2
MUC: Use events for hooking stanzas instead of the component stanza handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3510
diff
changeset
|
148 local origin, stanza = event.origin, event.stanza; |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
149 local room_jid = jid_bare(stanza.attr.to); |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
150 if stanza.attr.type == nil and |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
151 get_room_from_jid(room_jid) == nil and |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
152 ( |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
153 not(restrict_room_creation) or |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
154 is_admin(stanza.attr.from) or |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
155 ( |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
156 restrict_room_creation == "local" and |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
157 select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "") |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
158 ) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
159 ) then |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
160 create_room(room_jid); |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
161 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
162 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
163 module:hook("presence/full", attempt_room_creation, -1) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
164 module:hook("presence/bare", attempt_room_creation, -1) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
165 module:hook("presence/host", attempt_room_creation, -1) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
166 |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
167 for event_name, method in pairs { |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
168 -- Normal room interactions |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
169 ["iq-get/bare/http://jabber.org/protocol/disco#info:query"] = "handle_disco_info_get_query" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
170 ["iq-get/bare/http://jabber.org/protocol/disco#items:query"] = "handle_disco_items_get_query" ; |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
171 ["iq-set/bare/http://jabber.org/protocol/muc#admin:query"] = "handle_admin_query_set_command" ; |
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
172 ["iq-get/bare/http://jabber.org/protocol/muc#admin:query"] = "handle_admin_query_get_command" ; |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
173 ["iq-set/bare/http://jabber.org/protocol/muc#owner:query"] = "handle_owner_query_set_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
174 ["iq-get/bare/http://jabber.org/protocol/muc#owner:query"] = "handle_owner_query_get_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
175 ["message/bare"] = "handle_message_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
176 ["presence/bare"] = "handle_presence_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
177 -- Host room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
178 ["iq-get/host/http://jabber.org/protocol/disco#info:query"] = "handle_disco_info_get_query" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
179 ["iq-get/host/http://jabber.org/protocol/disco#items:query"] = "handle_disco_items_get_query" ; |
6141
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
180 ["iq-set/host/http://jabber.org/protocol/muc#admin:query"] = "handle_admin_query_set_command" ; |
bf6de8ef66c2
plugins/muc: Rename admin query hook
daurnimator <quae@daurnimator.com>
parents:
6129
diff
changeset
|
181 ["iq-get/host/http://jabber.org/protocol/muc#admin:query"] = "handle_admin_query_get_command" ; |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
182 ["iq-set/host/http://jabber.org/protocol/muc#owner:query"] = "handle_owner_query_set_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
183 ["iq-get/host/http://jabber.org/protocol/muc#owner:query"] = "handle_owner_query_get_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
184 ["message/host"] = "handle_message_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
185 ["presence/host"] = "handle_presence_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
186 -- Direct to occupant (normal rooms and host room) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
187 ["presence/full"] = "handle_presence_to_occupant" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
188 ["iq/full"] = "handle_iq_to_occupant" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
189 ["message/full"] = "handle_message_to_occupant" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
190 } do |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
191 module:hook(event_name, function (event) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
192 local origin, stanza = event.origin, event.stanza; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
193 local room = get_room_from_jid(jid_bare(stanza.attr.to)) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
194 if room == nil then |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
195 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); |
5058
433cc9a4c7e9
MUC: Return <item-not-found/> on message and iq to non-existent rooms (thanks Maranda).
Waqas Hussain <waqas20@gmail.com>
parents:
5016
diff
changeset
|
196 return true; |
433cc9a4c7e9
MUC: Return <item-not-found/> on message and iq to non-existent rooms (thanks Maranda).
Waqas Hussain <waqas20@gmail.com>
parents:
5016
diff
changeset
|
197 end |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
198 return room[method](room, origin, stanza); |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
199 end, -2) |
3560
fb49b63e3fe2
MUC: Use events for hooking stanzas instead of the component stanza handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3510
diff
changeset
|
200 end |
6091
3a1c39b31497
plugins/muc/mod_muc: Move Xep-0307 MUC unique to seperate file
daurnimator <quae@daurnimator.com>
parents:
6000
diff
changeset
|
201 |
5016
56a0b13a3d42
mod_muc: Remove unused variable and pull hosts into a local
Kim Alvefur <zash@zash.se>
parents:
5015
diff
changeset
|
202 hosts[module:get_host()].muc = { rooms = rooms }; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
203 |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
204 local saved = false; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
205 module.save = function() |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
206 saved = true; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
207 return {rooms = rooms}; |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
208 end |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
209 module.restore = function(data) |
1748
f4c50c75af6f
MUC: Fixed stanza routing for reloaded rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1747
diff
changeset
|
210 for jid, oldroom in pairs(data.rooms or {}) do |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
211 local room = create_room(jid); |
1747
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
212 room._jid_nick = oldroom._jid_nick; |
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
213 room._occupants = oldroom._occupants; |
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
214 room._data = oldroom._data; |
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
215 room._affiliations = oldroom._affiliations; |
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
216 end |
5016
56a0b13a3d42
mod_muc: Remove unused variable and pull hosts into a local
Kim Alvefur <zash@zash.se>
parents:
5015
diff
changeset
|
217 hosts[module:get_host()].muc = { rooms = rooms }; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
218 end |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
219 |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
220 function shutdown_component() |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
221 if not saved then |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
222 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
5659
9f9de8078164
mod_muc: Include status code 332 on service shutdown (thanks mathieui)
Matthew Wild <mwild1@gmail.com>
parents:
5580
diff
changeset
|
223 :tag("status", { code = "332"}):up(); |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
224 for roomjid, room in pairs(rooms) do |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
225 room:clear(x); |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
226 end |
6179
e488a90195bc
plugins/muc: Massive refactor
daurnimator <quae@daurnimator.com>
parents:
6141
diff
changeset
|
227 host_room:clear(x); |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
228 end |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
229 end |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
230 module.unload = shutdown_component; |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
231 module:hook_global("server-stopping", shutdown_component); |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
232 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
233 -- Ad-hoc commands |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
234 module:depends("adhoc") |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
235 local t_concat = table.concat; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
236 local keys = require "util.iterators".keys; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
237 local adhoc_new = module:require "adhoc".new; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
238 local adhoc_initial = require "util.adhoc".new_initial_data_form; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
239 local dataforms_new = require "util.dataforms".new; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
240 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
241 local destroy_rooms_layout = dataforms_new { |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
242 title = "Destroy rooms"; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
243 instructions = "Select the rooms to destroy"; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
244 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
245 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
246 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"}; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
247 }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
248 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
249 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
250 return { rooms = array.collect(keys(rooms)):sort() }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
251 end, function(fields, errors) |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
252 if errors then |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
253 local errmsg = {}; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
254 for name, err in pairs(errors) do |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
255 errmsg[#errmsg + 1] = name .. ": " .. err; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
256 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
257 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
258 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
259 for _, room in ipairs(fields.rooms) do |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
260 rooms[room]:destroy(); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
261 rooms[room] = nil; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
262 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
263 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
264 end); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
265 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
266 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
267 module:provides("adhoc", destroy_rooms_desc); |