Mercurial > prosody-hg
annotate plugins/muc/mod_muc.lua @ 13946:f5e8ab42c708
mod_http_file_share: Check that files are still there with correct size
Failed uploads can leave behind unused slots. Files shouldn't change
size after they have been successfully uploaded, but might as well
double check it.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 04 Dec 2021 18:56:51 +0100 |
| parents | 356c8ec22e9a |
| children | f5d415d54064 |
| 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 |
|
8572
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
9 -- Exposed functions: |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
10 -- |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
11 -- create_room(jid) -> room |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
12 -- track_room(room) |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
13 -- delete_room(room) |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
14 -- forget_room(room) |
|
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
15 -- get_room_from_jid(jid) -> room |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
16 -- each_room(live_only) -> () -> room [DEPRECATED] |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
17 -- all_rooms() -> room |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
18 -- live_rooms() -> room |
|
8572
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
19 -- shutdown_component() |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 |
|
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 if module:get_host_type() ~= "component" then |
|
7359
a5a080c12c96
Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7350
diff
changeset
|
22 error("MUC should be loaded as a component, please see https://prosody.im/doc/components", 0); |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
|
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 |
|
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
25 local muclib = module:require "muc"; |
|
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
26 room_mt = muclib.room_mt; -- Yes, global. |
|
8879
4dee8c439afc
MUC: Expose method for creating a bare room object
Kim Alvefur <zash@zash.se>
parents:
8877
diff
changeset
|
27 new_room = muclib.new_room; |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
28 |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
29 local name = module:require "muc/name"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
30 room_mt.get_name = name.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
31 room_mt.set_name = name.set; |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
33 local description = module:require "muc/description"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
34 room_mt.get_description = description.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
35 room_mt.set_description = description.set; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
36 |
|
8833
9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
37 local language = module:require "muc/language"; |
|
9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
38 room_mt.get_language = language.get; |
|
9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
39 room_mt.set_language = language.set; |
|
9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
40 |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
41 local hidden = module:require "muc/hidden"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
42 room_mt.get_hidden = hidden.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
43 room_mt.set_hidden = hidden.set; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
44 function room_mt:get_public() |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
45 return not self:get_hidden(); |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
46 end |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
47 function room_mt:set_public(public) |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
48 return self:set_hidden(not public); |
|
3575
bc3dfc00da5d
MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
Waqas Hussain <waqas20@gmail.com>
parents:
3560
diff
changeset
|
49 end |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
51 local password = module:require "muc/password"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
52 room_mt.get_password = password.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
53 room_mt.set_password = password.set; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
54 |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
55 local members_only = module:require "muc/members_only"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
56 room_mt.get_members_only = members_only.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
57 room_mt.set_members_only = members_only.set; |
|
8976
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
8944
diff
changeset
|
58 room_mt.get_allow_member_invites = members_only.get_allow_member_invites; |
|
92f0876b9230
MUC: Add config option to allow members to invite other members to the room (previously only owners/admins could do this)
Matthew Wild <mwild1@gmail.com>
parents:
8944
diff
changeset
|
59 room_mt.set_allow_member_invites = members_only.set_allow_member_invites; |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
60 |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
61 local moderated = module:require "muc/moderated"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
62 room_mt.get_moderated = moderated.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
63 room_mt.set_moderated = moderated.set; |
|
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
|
64 |
|
8865
2a8bbfcb6868
MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents:
8843
diff
changeset
|
65 local request = module:require "muc/request"; |
|
2a8bbfcb6868
MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents:
8843
diff
changeset
|
66 room_mt.handle_role_request = request.handle_request; |
|
2a8bbfcb6868
MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents:
8843
diff
changeset
|
67 |
|
6769
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
68 local persistent = module:require "muc/persistent"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
69 room_mt.get_persistent = persistent.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
70 room_mt.set_persistent = persistent.set; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
71 |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
72 local subject = module:require "muc/subject"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
73 room_mt.get_changesubject = subject.get_changesubject; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
74 room_mt.set_changesubject = subject.set_changesubject; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
75 room_mt.get_subject = subject.get; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
76 room_mt.set_subject = subject.set; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
77 room_mt.send_subject = subject.send; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
78 |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
79 local history = module:require "muc/history"; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
80 room_mt.send_history = history.send; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
81 room_mt.get_historylength = history.get_length; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
82 room_mt.set_historylength = history.set_length; |
|
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
83 |
|
9240
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
84 local register = module:require "muc/register"; |
|
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
85 room_mt.get_registered_nick = register.get_registered_nick; |
|
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
86 room_mt.get_registered_jid = register.get_registered_jid; |
|
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
87 room_mt.handle_register_iq = register.handle_register_iq; |
|
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
88 |
|
13495
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
89 local restrict_pm = module:require "muc/restrict_pm"; |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
90 room_mt.get_allow_pm = restrict_pm.get_allow_pm; |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
91 room_mt.set_allow_pm = restrict_pm.set_allow_pm; |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
92 room_mt.get_allow_modpm = restrict_pm.get_allow_modpm; |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
93 room_mt.set_allow_modpm = restrict_pm.set_allow_modpm; |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
94 |
|
10353
7b602e13c3b6
MUC: Add controls for whose presence is broadcast (closes #1335)
Lance Stout <lancestout@gmail.com>
parents:
9647
diff
changeset
|
95 local presence_broadcast = module:require "muc/presence_broadcast"; |
|
7b602e13c3b6
MUC: Add controls for whose presence is broadcast (closes #1335)
Lance Stout <lancestout@gmail.com>
parents:
9647
diff
changeset
|
96 room_mt.get_presence_broadcast = presence_broadcast.get; |
|
7b602e13c3b6
MUC: Add controls for whose presence is broadcast (closes #1335)
Lance Stout <lancestout@gmail.com>
parents:
9647
diff
changeset
|
97 room_mt.set_presence_broadcast = presence_broadcast.set; |
|
12854
73db76cc6472
MUC: Add note about non-existant room method
Kim Alvefur <zash@zash.se>
parents:
12731
diff
changeset
|
98 room_mt.get_valid_broadcast_roles = presence_broadcast.get_valid_broadcast_roles; -- FIXME doesn't exist in the library |
|
10353
7b602e13c3b6
MUC: Add controls for whose presence is broadcast (closes #1335)
Lance Stout <lancestout@gmail.com>
parents:
9647
diff
changeset
|
99 |
|
11215
9ce0a899ff07
MUC: Merge mod_muc_occupant_id into a sub-module (thanks pep.!)
Matthew Wild <mwild1@gmail.com>
parents:
11057
diff
changeset
|
100 local occupant_id = module:require "muc/occupant_id"; |
|
12108
e9882c4c397f
MUC: Add method for getting the occupant id salt to allow reuse
Kim Alvefur <zash@zash.se>
parents:
12010
diff
changeset
|
101 room_mt.get_salt = occupant_id.get_room_salt; |
|
11215
9ce0a899ff07
MUC: Merge mod_muc_occupant_id into a sub-module (thanks pep.!)
Matthew Wild <mwild1@gmail.com>
parents:
11057
diff
changeset
|
102 room_mt.get_occupant_id = occupant_id.get_occupant_id; |
|
13905
0e346f4d88ce
MUC: Add get_occupant_id_from_jid() method, which works on real JIDs
Matthew Wild <mwild1@gmail.com>
parents:
13894
diff
changeset
|
103 room_mt.get_occupant_id_from_jid = occupant_id.get_occupant_id_from_jid; |
|
10353
7b602e13c3b6
MUC: Add controls for whose presence is broadcast (closes #1335)
Lance Stout <lancestout@gmail.com>
parents:
9647
diff
changeset
|
104 |
|
13908
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
13905
diff
changeset
|
105 if module:get_option_boolean("muc_enable_experimental_gc3", false) then |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
13905
diff
changeset
|
106 module:require "muc/gc3"; |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
13905
diff
changeset
|
107 end |
|
356c8ec22e9a
MUC: Add basic "GC3" participant (affiliation) list fetch
Matthew Wild <mwild1@gmail.com>
parents:
13905
diff
changeset
|
108 |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
109 local jid_split = require "prosody.util.jid".split; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
110 local jid_prep = require "prosody.util.jid".prep; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
111 local jid_bare = require "prosody.util.jid".bare; |
|
13876
3609d8fcad00
MUC: Ensure room-creating join stanza includes nickname (fix #1934)
Kim Alvefur <zash@zash.se>
parents:
13875
diff
changeset
|
112 local jid_resource = require "prosody.util.jid".resource; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
113 local st = require "prosody.util.stanza"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
114 local cache = require "prosody.util.cache"; |
|
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
|
115 |
|
9035
173c0e16e704
MUC: Add sections in room config form
Matthew Wild <mwild1@gmail.com>
parents:
9019
diff
changeset
|
116 module:require "muc/config_form_sections"; |
|
173c0e16e704
MUC: Add sections in room config form
Matthew Wild <mwild1@gmail.com>
parents:
9019
diff
changeset
|
117 |
|
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
118 module:depends("disco"); |
|
6235
d433db49e353
plugins/muc/mod_muc: Use get_option_string instead of get_option and checking
daurnimator <quae@daurnimator.com>
parents:
6234
diff
changeset
|
119 module:add_identity("conference", "text", module:get_option_string("name", "Prosody Chatrooms")); |
|
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
120 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
|
121 module:depends "muc_unique" |
|
10693
76bb806cdd4b
MUC: Add initial hats support (broadcast only)
Matthew Wild <mwild1@gmail.com>
parents:
10647
diff
changeset
|
122 module:require "muc/hats"; |
|
6206
f937bb5c83c3
plugins/muc: Move locking to seperate module
daurnimator <quae@daurnimator.com>
parents:
6205
diff
changeset
|
123 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
|
124 |
|
13657
404d3644ac4a
mod_muc: Integrate support for vcards/avatars on MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
13496
diff
changeset
|
125 if module:get_option_boolean("muc_vcard", true) ~= false then |
|
404d3644ac4a
mod_muc: Integrate support for vcards/avatars on MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
13496
diff
changeset
|
126 module:require "muc/vcard"; |
|
404d3644ac4a
mod_muc: Integrate support for vcards/avatars on MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
13496
diff
changeset
|
127 end |
|
404d3644ac4a
mod_muc: Integrate support for vcards/avatars on MUC rooms
Matthew Wild <mwild1@gmail.com>
parents:
13496
diff
changeset
|
128 |
|
12642
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
129 module:default_permissions("prosody:admin", { |
|
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
130 ":automatic-ownership"; |
|
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
131 ":create-room"; |
|
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
132 ":recreate-destroyed-room"; |
|
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
133 }); |
|
13307
8fb8a253f0a1
mod_muc: Allow guest users to list rooms by default
Matthew Wild <mwild1@gmail.com>
parents:
13306
diff
changeset
|
134 module:default_permissions("prosody:guest", { |
|
8fb8a253f0a1
mod_muc: Allow guest users to list rooms by default
Matthew Wild <mwild1@gmail.com>
parents:
13306
diff
changeset
|
135 ":list-rooms"; |
|
8fb8a253f0a1
mod_muc: Allow guest users to list rooms by default
Matthew Wild <mwild1@gmail.com>
parents:
13306
diff
changeset
|
136 }); |
|
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
|
137 |
|
13496
3e6d5738ea09
MUC: Don't default component admins to being room owners
Matthew Wild <mwild1@gmail.com>
parents:
13495
diff
changeset
|
138 if module:get_option_boolean("component_admins_as_room_owners", false) then |
|
10646
85585910d468
mod_muc: Allow control over the server-admins-are-room-owners feature (see #1174)
Matthew Wild <mwild1@gmail.com>
parents:
9626
diff
changeset
|
139 -- Monkey patch to make server admins room owners |
|
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
140 local _get_affiliation = room_mt.get_affiliation; |
|
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
141 function room_mt:get_affiliation(jid) |
|
13308
d539cb48c6e9
mod_muc: Switch to module:could() for some implicit access control checks
Matthew Wild <mwild1@gmail.com>
parents:
13307
diff
changeset
|
142 if module:could(":automatic-ownership", jid) then return "owner"; end |
|
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
143 return _get_affiliation(self, jid); |
|
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
144 end |
|
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
145 |
|
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
146 local _set_affiliation = room_mt.set_affiliation; |
|
9237
b86c2e135797
MUC: Add support for storing additional data with MUC affiliations
Matthew Wild <mwild1@gmail.com>
parents:
9221
diff
changeset
|
147 function room_mt:set_affiliation(actor, jid, affiliation, reason, data) |
|
13308
d539cb48c6e9
mod_muc: Switch to module:could() for some implicit access control checks
Matthew Wild <mwild1@gmail.com>
parents:
13307
diff
changeset
|
148 if affiliation ~= "owner" and module:could(":automatic-ownership", jid) then return nil, "modify", "not-acceptable"; end |
|
9237
b86c2e135797
MUC: Add support for storing additional data with MUC affiliations
Matthew Wild <mwild1@gmail.com>
parents:
9221
diff
changeset
|
149 return _set_affiliation(self, actor, jid, affiliation, reason, data); |
|
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
150 end |
|
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
151 end |
|
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
152 |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
153 local persistent_rooms_storage = module:open_store("persistent"); |
|
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
154 local persistent_rooms = module:open_store("persistent", "map"); |
|
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
155 local room_configs = module:open_store("config"); |
|
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
156 local room_state = module:open_store("state"); |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
157 |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
158 local room_items_cache = {}; |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
159 |
|
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
160 local function room_save(room, forced, savestate) |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
161 local node = jid_split(room.jid); |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
162 local is_persistent = persistent.get(room); |
|
11057
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
163 if room:get_public() then |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
164 room_items_cache[room.jid] = room:get_name() or ""; |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
165 else |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
166 room_items_cache[room.jid] = nil; |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
167 end |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
168 |
|
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
169 if is_persistent or savestate then |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
170 persistent_rooms:set(nil, room.jid, true); |
|
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
171 local data, state = room:freeze(savestate); |
|
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
172 room_state:set(node, state); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
173 return room_configs:set(node, data); |
|
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
174 elseif forced then |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
175 persistent_rooms:set(nil, room.jid, nil); |
|
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
176 room_state:set(node, nil); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
177 return room_configs:set(node, nil); |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
178 end |
|
6742
6efeb801d62f
Backed out changeset bea3862b6bde in favor of a different approach
Kim Alvefur <zash@zash.se>
parents:
6741
diff
changeset
|
179 end |
|
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
180 |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
181 local max_rooms = module:get_option_integer("muc_max_rooms", nil, 0); |
|
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
182 local max_live_rooms = module:get_option_integer("muc_room_cache_size", 100, 1); |
|
8818
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
183 |
|
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
184 local room_hit = module:measure("room_hit", "rate"); |
|
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
185 local room_miss = module:measure("room_miss", "rate") |
|
8925
d367aeb9c50f
MUC: Rename eviction hit rate measure
Kim Alvefur <zash@zash.se>
parents:
8879
diff
changeset
|
186 local room_eviction = module:measure("room_eviction", "rate"); |
|
8818
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
187 local rooms = cache.new(max_rooms or max_live_rooms, function (jid, room) |
|
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
188 if max_rooms then |
|
9191
5192adc5c47f
MUC: Pass missing argument to log message
Kim Alvefur <zash@zash.se>
parents:
9093
diff
changeset
|
189 module:log("info", "Room limit of %d reached, no new rooms allowed", max_rooms); |
|
8818
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
190 return false; |
|
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
191 end |
| 8385 | 192 module:log("debug", "Evicting room %s", jid); |
|
8925
d367aeb9c50f
MUC: Rename eviction hit rate measure
Kim Alvefur <zash@zash.se>
parents:
8879
diff
changeset
|
193 room_eviction(); |
|
11057
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
194 if room:get_public() then |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
195 room_items_cache[room.jid] = room:get_name() or ""; |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
196 else |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
197 room_items_cache[room.jid] = nil; |
|
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
198 end |
|
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
199 local ok, err = room_save(room, nil, true); -- Force to disk |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
200 if not ok then |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
201 module:log("error", "Failed to swap inactive room %s to disk: %s", jid, err); |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
202 return false; |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
203 end |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
204 end); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
205 |
|
11492
6da8d9cb355d
MUC: Report number of live rooms to statsmanager
Kim Alvefur <zash@zash.se>
parents:
11215
diff
changeset
|
206 local measure_rooms_size = module:measure("live_room", "amount"); |
|
6da8d9cb355d
MUC: Report number of live rooms to statsmanager
Kim Alvefur <zash@zash.se>
parents:
11215
diff
changeset
|
207 module:hook_global("stats-update", function () |
|
6da8d9cb355d
MUC: Report number of live rooms to statsmanager
Kim Alvefur <zash@zash.se>
parents:
11215
diff
changeset
|
208 measure_rooms_size(rooms:count()); |
|
6da8d9cb355d
MUC: Report number of live rooms to statsmanager
Kim Alvefur <zash@zash.se>
parents:
11215
diff
changeset
|
209 end); |
|
6da8d9cb355d
MUC: Report number of live rooms to statsmanager
Kim Alvefur <zash@zash.se>
parents:
11215
diff
changeset
|
210 |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
211 -- Automatically destroy empty non-persistent rooms |
|
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
212 module:hook("muc-occupant-left",function(event) |
|
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
213 local room = event.room |
|
9007
695904638cfa
MUC: Flag rooms being destroyed (fixes #887)
Kim Alvefur <zash@zash.se>
parents:
8977
diff
changeset
|
214 if room.destroying then return end |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
215 if not room:has_occupant() and not persistent.get(room) then -- empty, non-persistent room |
|
9010
3c5ddd53fe50
MUC: Log a debug message when a non-persistent room becomes empty and is destroyed
Kim Alvefur <zash@zash.se>
parents:
9007
diff
changeset
|
216 module:log("debug", "%q empty, destroying", room.jid); |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
217 module:fire_event("muc-room-destroyed", { room = room }); |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
218 end |
|
7417
4c8ee8175f5e
MUC: Lower priority of hook so plugins hooks run before
Kim Alvefur <zash@zash.se>
parents:
7415
diff
changeset
|
219 end, -1); |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
220 |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
221 function track_room(room) |
|
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
222 if rooms:set(room.jid, room) then |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
223 -- When room is created, over-ride 'save' method |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
224 room.save = room_save; |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
225 return room; |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
226 end |
| 9078 | 227 -- Resource limit reached |
|
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
228 return false; |
|
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
229 end |
|
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
230 |
|
8661
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
231 local function handle_broken_room(room, origin, stanza) |
|
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
232 module:log("debug", "Returning error from broken room %s", room.jid); |
|
10449
2e36a54906e4
MUC: Indicate that the room is the origin of various errors where 'from' is an occupant JID
Kim Alvefur <zash@zash.se>
parents:
10366
diff
changeset
|
233 origin.send(st.error_reply(stanza, "wait", "internal-server-error", nil, room.jid)); |
|
8661
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
234 return true; |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
235 end |
|
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
236 |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
237 local function restore_room(jid) |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
238 local node = jid_split(jid); |
|
8656
0e84814a7ece
MUC: Produce an untracked, locked room on failure to read room from storage (#1091)
Kim Alvefur <zash@zash.se>
parents:
8572
diff
changeset
|
239 local data, err = room_configs:get(node); |
|
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
240 if data then |
|
8178
9f2a5fc9e4a5
MUC: Log debug message when restoring a room from storage
Kim Alvefur <zash@zash.se>
parents:
8026
diff
changeset
|
241 module:log("debug", "Restoring room %s from storage", jid); |
|
9079
c040c358d6c0
mod_muc: Fire event when room is (and about to be) restored
Matthew Wild <mwild1@gmail.com>
parents:
9078
diff
changeset
|
242 if module:fire_event("muc-room-pre-restore", { jid = jid, data = data }) == false then |
|
c040c358d6c0
mod_muc: Fire event when room is (and about to be) restored
Matthew Wild <mwild1@gmail.com>
parents:
9078
diff
changeset
|
243 return false; |
|
c040c358d6c0
mod_muc: Fire event when room is (and about to be) restored
Matthew Wild <mwild1@gmail.com>
parents:
9078
diff
changeset
|
244 end |
|
8659
4006755c1097
MUC: Log failure to load room state
Kim Alvefur <zash@zash.se>
parents:
8658
diff
changeset
|
245 local state, s_err = room_state:get(node); |
|
4006755c1097
MUC: Log failure to load room state
Kim Alvefur <zash@zash.se>
parents:
8658
diff
changeset
|
246 if not state and s_err then |
|
4006755c1097
MUC: Log failure to load room state
Kim Alvefur <zash@zash.se>
parents:
8658
diff
changeset
|
247 module:log("debug", "Could not restore state of room %s: %s", jid, s_err); |
|
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
|
248 end |
|
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
249 local room = muclib.restore_room(data, state); |
|
9013
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
250 if track_room(room) then |
|
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
251 room_state:set(node, nil); |
|
9079
c040c358d6c0
mod_muc: Fire event when room is (and about to be) restored
Matthew Wild <mwild1@gmail.com>
parents:
9078
diff
changeset
|
252 module:fire_event("muc-room-restored", { jid = jid, room = room }); |
|
9013
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
253 return room; |
|
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
254 else |
|
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
255 return false; |
|
a54bcc76cd22
MUC: Remove room state on successful restoration from disk
Kim Alvefur <zash@zash.se>
parents:
9012
diff
changeset
|
256 end |
|
8656
0e84814a7ece
MUC: Produce an untracked, locked room on failure to read room from storage (#1091)
Kim Alvefur <zash@zash.se>
parents:
8572
diff
changeset
|
257 elseif err then |
|
0e84814a7ece
MUC: Produce an untracked, locked room on failure to read room from storage (#1091)
Kim Alvefur <zash@zash.se>
parents:
8572
diff
changeset
|
258 module:log("error", "Error restoring room %s from storage: %s", jid, err); |
|
0e84814a7ece
MUC: Produce an untracked, locked room on failure to read room from storage (#1091)
Kim Alvefur <zash@zash.se>
parents:
8572
diff
changeset
|
259 local room = muclib.new_room(jid, { locked = math.huge }); |
|
8661
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
260 room.handle_normal_presence = handle_broken_room; |
|
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
261 room.handle_first_presence = handle_broken_room; |
|
8656
0e84814a7ece
MUC: Produce an untracked, locked room on failure to read room from storage (#1091)
Kim Alvefur <zash@zash.se>
parents:
8572
diff
changeset
|
262 return room; |
|
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
|
263 end |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
264 end |
|
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
265 |
|
9051
68386f7b9fc9
MUC: Add some comments clarifying methods
Matthew Wild <mwild1@gmail.com>
parents:
9050
diff
changeset
|
266 -- Removes a room from memory, without saving it (save first if required) |
|
6348
bffc885dc378
mod_muc: Fix tracebacks (thanks nick1)
Kim Alvefur <zash@zash.se>
parents:
6334
diff
changeset
|
267 function forget_room(room) |
|
7536
3f8520b59677
MUC: Pass room JID instead of room itself to logger, fixes traceback (thanks damencho)
Kim Alvefur <zash@zash.se>
parents:
7417
diff
changeset
|
268 module:log("debug", "Forgetting %s", room.jid); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
269 rooms.save = nil; |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
270 rooms:set(room.jid, nil); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
271 end |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
272 |
|
9051
68386f7b9fc9
MUC: Add some comments clarifying methods
Matthew Wild <mwild1@gmail.com>
parents:
9050
diff
changeset
|
273 -- Removes a room from the database (may remain in memory) |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
274 function delete_room(room) |
|
7650
4c2407422f71
Logging error if MUC room cache is full
Sam Whited <sam@samwhited.com>
parents:
7641
diff
changeset
|
275 module:log("debug", "Deleting %s", room.jid); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
276 room_configs:set(jid_split(room.jid), nil); |
|
9012
295faf1522f9
MUC: Purge saved room state when deleting a room
Kim Alvefur <zash@zash.se>
parents:
9010
diff
changeset
|
277 room_state:set(jid_split(room.jid), nil); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
278 persistent_rooms:set(nil, room.jid, nil); |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
279 room_items_cache[room.jid] = nil; |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
280 end |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
281 |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
282 function module.unload() |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
283 for room in live_rooms() do |
|
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
284 room:save(nil, true); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
285 forget_room(room); |
|
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
|
286 end |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
287 end |
|
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
288 |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
289 function get_room_from_jid(room_jid) |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
290 local room = rooms:get(room_jid); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
291 if room then |
|
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
292 room_hit(); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
293 rooms:set(room_jid, room); -- bump to top; |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
294 return room; |
|
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
295 end |
|
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
296 room_miss(); |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
297 return restore_room(room_jid); |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
298 end |
|
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
299 |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
300 local function set_room_defaults(room, lang) |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
301 room:set_public(module:get_option_boolean("muc_room_default_public", false)); |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
302 room:set_persistent(module:get_option_boolean("muc_room_default_persistent", room:get_persistent())); |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
303 room:set_members_only(module:get_option_boolean("muc_room_default_members_only", room:get_members_only())); |
|
13229
bb7177efbf41
plugins: Use boolean config method in some places
Kim Alvefur <zash@zash.se>
parents:
13226
diff
changeset
|
304 room:set_allow_member_invites(module:get_option_boolean("muc_room_default_allow_member_invites", room:get_allow_member_invites())); |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
305 room:set_moderated(module:get_option_boolean("muc_room_default_moderated", room:get_moderated())); |
|
13229
bb7177efbf41
plugins: Use boolean config method in some places
Kim Alvefur <zash@zash.se>
parents:
13226
diff
changeset
|
306 room:set_whois(module:get_option_boolean("muc_room_default_public_jids", room:get_whois() == "anyone") and "anyone" or "moderators"); |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
307 room:set_changesubject(module:get_option_boolean("muc_room_default_change_subject", room:get_changesubject())); |
|
13213
50324f66ca2a
plugins: Use integer config API with interval specification where sensible
Kim Alvefur <zash@zash.se>
parents:
13209
diff
changeset
|
308 room:set_historylength(module:get_option_integer("muc_room_default_history_length", room:get_historylength(), 0)); |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
309 room:set_language(lang or module:get_option_string("muc_room_default_language")); |
|
13894
c6010e1322aa
MUC: Fix #1938 by reverting ac44bb7b7064
Kim Alvefur <zash@zash.se>
parents:
13876
diff
changeset
|
310 room:set_presence_broadcast(module:get_option("muc_room_default_presence_broadcast", room:get_presence_broadcast())); |
|
13495
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
311 room:set_allow_pm(module:get_option_enum("muc_room_default_allow_pm", room:get_allow_pm(), "visitor", "participant", "moderator")); |
|
47e1df2d0a37
MUC: Add per-room PM restriction functionality (thanks Wirlaburla)
Matthew Wild <mwild1@gmail.com>
parents:
13308
diff
changeset
|
312 room:set_allow_modpm(module:get_option_boolean("muc_room_default_always_allow_moderator_pms", room:get_allow_modpm())); |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
313 end |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
314 |
|
8875
be3230b42f12
MUC: Allow passing config to public create_room API
Kim Alvefur <zash@zash.se>
parents:
8870
diff
changeset
|
315 function create_room(room_jid, config) |
|
10366
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
316 if jid_bare(room_jid) ~= room_jid or not jid_prep(room_jid, true) then |
|
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
317 return nil, "invalid-jid"; |
|
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
318 end |
|
7641
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
319 local exists = get_room_from_jid(room_jid); |
|
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
320 if exists then |
|
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
321 return nil, "room-exists"; |
|
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
322 end |
|
8875
be3230b42f12
MUC: Allow passing config to public create_room API
Kim Alvefur <zash@zash.se>
parents:
8870
diff
changeset
|
323 local room = muclib.new_room(room_jid, config); |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
324 if not config then |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
325 set_room_defaults(room); |
|
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
326 end |
|
7641
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
327 module:fire_event("muc-room-created", { |
|
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
328 room = room; |
|
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
329 }); |
|
8877
9182398c64b9
MUC: Track rooms created via internal public API
Kim Alvefur <zash@zash.se>
parents:
8875
diff
changeset
|
330 return track_room(room); |
|
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
331 end |
|
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
332 |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
333 function all_rooms() |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
334 return coroutine.wrap(function () |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
335 local seen = {}; -- Don't iterate over persistent rooms twice |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
336 for room in live_rooms() do |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
337 coroutine.yield(room); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
338 seen[room.jid] = true; |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
339 end |
|
8662
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
340 local all_persistent_rooms, err = persistent_rooms_storage:get(nil); |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
341 if not all_persistent_rooms then |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
342 if err then |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
343 module:log("error", "Error loading list of persistent rooms, only rooms live in memory were iterated over"); |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
344 module:log("debug", "%s", debug.traceback(err)); |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
345 end |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
346 return nil; |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
347 end |
|
a4e63b037a2a
MUC: Catch and log error in case of storage failure in iterator over rooms
Kim Alvefur <zash@zash.se>
parents:
8661
diff
changeset
|
348 for room_jid in pairs(all_persistent_rooms) do |
|
7403
d6e6e21057f0
MUC: Correctly iterate over suspended rooms while excluding live rooms
Kim Alvefur <zash@zash.se>
parents:
7372
diff
changeset
|
349 if not seen[room_jid] then |
|
6479
d016437e01bf
plugins/muc/mod_muc: Add 'local_only' flag to mod_muc, so rooms don't get restored on shutdown
daurnimator <quae@daurnimator.com>
parents:
6372
diff
changeset
|
350 local room = restore_room(room_jid); |
|
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
351 if room then |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
352 coroutine.yield(room); |
|
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
353 else |
|
6479
d016437e01bf
plugins/muc/mod_muc: Add 'local_only' flag to mod_muc, so rooms don't get restored on shutdown
daurnimator <quae@daurnimator.com>
parents:
6372
diff
changeset
|
354 module:log("error", "Missing data for room '%s', omitting from iteration", room_jid); |
|
d016437e01bf
plugins/muc/mod_muc: Add 'local_only' flag to mod_muc, so rooms don't get restored on shutdown
daurnimator <quae@daurnimator.com>
parents:
6372
diff
changeset
|
355 end |
|
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
356 end |
|
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
357 end |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
358 end); |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
359 end |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
360 |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
361 function live_rooms() |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
362 return rooms:values(); |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
363 end |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
364 |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
365 function each_room(live_only) |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
366 if live_only then |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
367 return live_rooms(); |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
368 end |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
369 return all_rooms(); |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
370 end |
|
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
371 |
|
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
372 module:hook("host-disco-items", function(event) |
|
13306
939df56a51ba
mod_muc: Add :list-rooms permission
Matthew Wild <mwild1@gmail.com>
parents:
13233
diff
changeset
|
373 module:log("debug", "host-disco-items called"); |
|
939df56a51ba
mod_muc: Add :list-rooms permission
Matthew Wild <mwild1@gmail.com>
parents:
13233
diff
changeset
|
374 if not module:could(":list-rooms", event) then |
|
939df56a51ba
mod_muc: Add :list-rooms permission
Matthew Wild <mwild1@gmail.com>
parents:
13233
diff
changeset
|
375 module:log("debug", "Returning empty room list to unauthorized request"); |
|
939df56a51ba
mod_muc: Add :list-rooms permission
Matthew Wild <mwild1@gmail.com>
parents:
13233
diff
changeset
|
376 return; |
|
939df56a51ba
mod_muc: Add :list-rooms permission
Matthew Wild <mwild1@gmail.com>
parents:
13233
diff
changeset
|
377 end |
|
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
378 local reply = event.reply; |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
379 if next(room_items_cache) ~= nil then |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
380 for jid, room_name in pairs(room_items_cache) do |
|
11057
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
381 if room_name == "" then room_name = nil; end |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
382 reply:tag("item", { jid = jid, name = room_name }):up(); |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
383 end |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
384 else |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
385 for room in all_rooms() do |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
386 if not room:get_hidden() then |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
387 local jid, room_name = room.jid, room:get_name(); |
|
11057
13eee48071c8
MUC: Don't default room name to JID localpart (API breaking change)
Kim Alvefur <zash@zash.se>
parents:
10698
diff
changeset
|
388 room_items_cache[jid] = room_name or ""; |
|
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
389 reply:tag("item", { jid = jid, name = room_name }):up(); |
|
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
390 end |
|
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
391 end |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
392 end |
|
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
393 end); |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
394 |
|
8867
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
395 module:hook("muc-room-pre-create", function (event) |
|
9626
4d3ab7153153
MUC: Use defaults from config in create_room() if no config provided
Matthew Wild <mwild1@gmail.com>
parents:
9240
diff
changeset
|
396 set_room_defaults(event.room, event.stanza.attr["xml:lang"]); |
|
8867
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
397 end, 1); |
|
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
398 |
|
8660
3b54f8472b51
MUC: Return error if unable to keep track of room due to storage failure
Kim Alvefur <zash@zash.se>
parents:
8659
diff
changeset
|
399 module:hook("muc-room-pre-create", function(event) |
| 4370 | 400 local origin, stanza = event.origin, event.stanza; |
|
8660
3b54f8472b51
MUC: Return error if unable to keep track of room due to storage failure
Kim Alvefur <zash@zash.se>
parents:
8659
diff
changeset
|
401 if not track_room(event.room) then |
|
10450
c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
Kim Alvefur <zash@zash.se>
parents:
10449
diff
changeset
|
402 origin.send(st.error_reply(stanza, "wait", "resource-constraint", nil, module.host)); |
|
8660
3b54f8472b51
MUC: Return error if unable to keep track of room due to storage failure
Kim Alvefur <zash@zash.se>
parents:
8659
diff
changeset
|
403 return true; |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
404 end |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
405 end, -1000); |
|
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
406 |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
407 module:hook("muc-room-destroyed",function(event) |
|
7370
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
408 local room = event.room; |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
409 forget_room(room); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
410 delete_room(room); |
|
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
411 end); |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
412 |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
413 if module:get_option_boolean("muc_tombstones", true) then |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
414 |
|
13209
c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Kim Alvefur <zash@zash.se>
parents:
13170
diff
changeset
|
415 local ttl = module:get_option_period("muc_tombstone_expiry", "31 days"); |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
416 |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
417 module:hook("muc-room-destroyed",function(event) |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
418 local room = event.room; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
419 if not room:get_persistent() then return end |
|
9093
04a284c5b88b
MUC: Allow destruction of tombstones (eg via telnet or adhoc command)
Kim Alvefur <zash@zash.se>
parents:
9081
diff
changeset
|
420 if room._data.destroyed then |
|
04a284c5b88b
MUC: Allow destruction of tombstones (eg via telnet or adhoc command)
Kim Alvefur <zash@zash.se>
parents:
9081
diff
changeset
|
421 return -- Allow destruction of tombstone |
|
04a284c5b88b
MUC: Allow destruction of tombstones (eg via telnet or adhoc command)
Kim Alvefur <zash@zash.se>
parents:
9081
diff
changeset
|
422 end |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
423 |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
424 local tombstone = new_room(room.jid, { |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
425 locked = os.time() + ttl; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
426 destroyed = true; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
427 reason = event.reason; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
428 newjid = event.newjid; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
429 -- password? |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
430 }); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
431 tombstone.save = room_save; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
432 tombstone:set_persistent(true); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
433 tombstone:set_hidden(true); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
434 tombstone:save(true); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
435 return true; |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
436 end, -10); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
437 end |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
438 |
|
13233
37d67b5f9768
mod_muc: Use enum config API for 'restrict_room_creation'
Kim Alvefur <zash@zash.se>
parents:
13229
diff
changeset
|
439 local restrict_room_creation = module:get_option_enum("restrict_room_creation", false, true, "local"); |
|
13170
082c7d856e61
core, plugins: Split prosody:user role into prosody:{guest,registered,member}
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
440 module:default_permission(restrict_room_creation == true and "prosody:admin" or "prosody:registered", ":create-room"); |
|
12731
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
441 module:hook("muc-room-pre-create", function(event) |
|
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
442 local origin, stanza = event.origin, event.stanza; |
|
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
443 if restrict_room_creation ~= false and not module:may(":create-room", event) then |
|
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
444 origin.send(st.error_reply(stanza, "cancel", "not-allowed", "Room creation is restricted", module.host)); |
|
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
445 return true; |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
446 end |
|
12731
a314f5bff9f0
mod_muc: Better map restrict_room_creation to role permissions (behaviour change)
Matthew Wild <mwild1@gmail.com>
parents:
12642
diff
changeset
|
447 end); |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
448 |
|
13875
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
449 local function is_join_presence(stanza) |
|
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
450 return stanza.name == "presence" |
|
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
451 and stanza.attr.type == nil |
|
13876
3609d8fcad00
MUC: Ensure room-creating join stanza includes nickname (fix #1934)
Kim Alvefur <zash@zash.se>
parents:
13875
diff
changeset
|
452 and jid_resource(stanza.attr.to) ~= nil |
|
13875
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
453 and stanza:get_child("x", "http://jabber.org/protocol/muc"); |
|
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
454 end |
|
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
455 |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
456 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
|
457 -- Normal room interactions |
|
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
458 ["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
|
459 ["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
|
460 ["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
|
461 ["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
|
462 ["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
|
463 ["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
|
464 ["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
|
465 ["presence/bare"] = "handle_presence_to_room" ; |
|
9240
f9a83aca4421
MUC: Add support for registering with a MUC, including reserving a nickname as per XEP-0045
Matthew Wild <mwild1@gmail.com>
parents:
9237
diff
changeset
|
466 ["iq/bare/jabber:iq:register:query"] = "handle_register_iq"; |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
467 -- Host room |
|
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
468 ["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
|
469 ["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
|
470 ["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
|
471 ["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
|
472 ["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
|
473 ["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
|
474 ["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
|
475 ["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
|
476 -- 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
|
477 ["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
|
478 ["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
|
479 ["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
|
480 } do |
|
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
481 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
|
482 local origin, stanza = event.origin, event.stanza; |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
483 local room_jid = jid_bare(stanza.attr.to); |
|
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
484 local room = get_room_from_jid(room_jid); |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
485 |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
486 if room and room._data.destroyed then |
|
9081
ce57c69a20e2
MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents:
9079
diff
changeset
|
487 if room._data.locked < os.time() |
|
12642
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12108
diff
changeset
|
488 or (module:may(":recreate-destroyed-room", event) and stanza.name == "presence" and stanza.attr.type == nil) then |
|
9048
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
489 -- Allow the room to be recreated by admin or after time has passed |
|
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
490 delete_room(room); |
|
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
491 room = nil; |
|
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
492 else |
|
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
493 if stanza.attr.type ~= "error" then |
|
10450
c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
Kim Alvefur <zash@zash.se>
parents:
10449
diff
changeset
|
494 local reply = st.error_reply(stanza, "cancel", "gone", room._data.reason, module.host) |
|
9019
d780c10709c1
MUC: Include redirect in 'gone' error for destroyed rooms
Kim Alvefur <zash@zash.se>
parents:
9018
diff
changeset
|
495 if room._data.newjid then |
|
d780c10709c1
MUC: Include redirect in 'gone' error for destroyed rooms
Kim Alvefur <zash@zash.se>
parents:
9018
diff
changeset
|
496 local uri = "xmpp:"..room._data.newjid.."?join"; |
|
d780c10709c1
MUC: Include redirect in 'gone' error for destroyed rooms
Kim Alvefur <zash@zash.se>
parents:
9018
diff
changeset
|
497 reply:get_child("error"):child_with_name("gone"):text(uri); |
|
d780c10709c1
MUC: Include redirect in 'gone' error for destroyed rooms
Kim Alvefur <zash@zash.se>
parents:
9018
diff
changeset
|
498 end |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
499 event.origin.send(reply); |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
500 end |
|
9048
c58be87e62d0
MUC: Return 'gone' error for destroyed rooms in other cases than attempted join
Kim Alvefur <zash@zash.se>
parents:
9035
diff
changeset
|
501 return true; |
|
9015
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
502 end |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
503 end |
|
dc606dc89f44
MUC: Add support for storing a tombstone for destroyed rooms (#1182)
Kim Alvefur <zash@zash.se>
parents:
9013
diff
changeset
|
504 |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
505 if room == nil then |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
506 -- Watch presence to create rooms |
|
10366
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
507 if not jid_prep(room_jid, true) then |
|
10450
c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
Kim Alvefur <zash@zash.se>
parents:
10449
diff
changeset
|
508 origin.send(st.error_reply(stanza, "modify", "jid-malformed", nil, module.host)); |
|
10366
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
509 return true; |
|
5611c939743a
MUC: Strictly validate room JID on creation
Kim Alvefur <zash@zash.se>
parents:
10353
diff
changeset
|
510 end |
|
13875
9a2075e3e383
MUC: Factor out identification of join stanza
Kim Alvefur <zash@zash.se>
parents:
13657
diff
changeset
|
511 if is_join_presence(stanza) then |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
512 room = muclib.new_room(room_jid); |
|
7410
45f543c82893
MUC: Split out handling of the room-creating presence into its own method
Kim Alvefur <zash@zash.se>
parents:
7404
diff
changeset
|
513 return room:handle_first_presence(origin, stanza); |
|
7246
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
514 elseif stanza.attr.type ~= "error" then |
|
10450
c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
Kim Alvefur <zash@zash.se>
parents:
10449
diff
changeset
|
515 origin.send(st.error_reply(stanza, "cancel", "item-not-found", nil, module.host)); |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
516 return true; |
|
7246
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
517 else |
|
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
518 return; |
|
6244
dfaacf042cfe
plugins/muc/mod_muc: Remove attempt_room_creation and create_room function. Instead have a 'track_room' function called from the end of the pre-create hook, and just create an un-tracked room object when we get a presence
daurnimator <quae@daurnimator.com>
parents:
6243
diff
changeset
|
519 end |
| 9221 | 520 elseif room == false then -- Error loading room |
|
10450
c1edeb9fe337
MUC: Indicate the component as origin of various errors where there's no room
Kim Alvefur <zash@zash.se>
parents:
10449
diff
changeset
|
521 origin.send(st.error_reply(stanza, "wait", "resource-constraint", nil, module.host)); |
| 9221 | 522 return true; |
|
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
|
523 end |
|
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
524 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
|
525 end, -2) |
|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
526 end |
|
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
527 |
|
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
528 function shutdown_component() |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
529 for room in live_rooms() do |
|
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
530 room:save(nil, true); |
|
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
531 end |
|
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
532 end |
|
7694
bffbea1187ca
MUC: Run component shutdown after mod_c2s has closed its sessions (prevents ghosts)
Kim Alvefur <zash@zash.se>
parents:
7650
diff
changeset
|
533 module:hook_global("server-stopping", shutdown_component, -300); |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
534 |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
535 do -- Ad-hoc commands |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
536 module:depends "adhoc"; |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
537 local t_concat = table.concat; |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
538 local adhoc_new = module:require "adhoc".new; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
539 local adhoc_initial = require "prosody.util.adhoc".new_initial_data_form; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
540 local adhoc_simple = require "prosody.util.adhoc".new_simple_form; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
541 local array = require "prosody.util.array"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12854
diff
changeset
|
542 local dataforms_new = require "prosody.util.dataforms".new; |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
543 |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
544 local destroy_rooms_layout = dataforms_new { |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
545 title = "Destroy rooms"; |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
546 instructions = "Select the rooms to destroy"; |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
547 |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
548 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" }; |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
549 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"}; |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
550 }; |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
551 |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
552 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() |
|
9050
f5c43e829d93
MUC: Add new iteration methods, all_rooms/live_rooms to eventually replace each_room
Matthew Wild <mwild1@gmail.com>
parents:
9049
diff
changeset
|
553 return { rooms = array.collect(all_rooms()):pluck("jid"):sort(); }; |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
554 end, function(fields, errors) |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
555 if errors then |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
556 local errmsg = {}; |
|
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
557 for field, err in pairs(errors) do |
|
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
558 errmsg[#errmsg + 1] = field .. ": " .. err; |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
559 end |
|
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
560 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
561 end |
|
12010
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
562 local destroyed = array(); |
|
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
563 for _, room_jid in ipairs(fields.rooms) do |
|
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
564 local room = get_room_from_jid(room_jid); |
|
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
565 if room and room:destroy() then |
|
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
566 destroyed:push(room.jid); |
|
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
567 end |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
568 end |
|
12010
f995d62044fa
MUC: Allow modules a chance to act prior to room destruction
Kim Alvefur <zash@zash.se>
parents:
11492
diff
changeset
|
569 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(destroyed, "\n") }; |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
570 end); |
|
9081
ce57c69a20e2
MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents:
9079
diff
changeset
|
571 local destroy_rooms_desc = adhoc_new("Destroy Rooms", |
|
ce57c69a20e2
MUC: Split long lines [luacheck strict]
Kim Alvefur <zash@zash.se>
parents:
9079
diff
changeset
|
572 "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); |
|
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
573 |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
574 module:provides("adhoc", destroy_rooms_desc); |
|
10698
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
575 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
576 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
577 local set_affiliation_layout = dataforms_new { |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
578 -- FIXME wordsmith title, instructions, labels etc |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
579 title = "Set affiliation"; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
580 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
581 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#set-affiliation" }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
582 { name = "room", type = "jid-single", required = true, label = "Room"}; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
583 { name = "jid", type = "jid-single", required = true, label = "JID"}; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
584 { name = "affiliation", type = "list-single", required = true, label = "Affiliation", |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
585 options = { "owner"; "admin"; "member"; "none"; "outcast"; }, |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
586 }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
587 { name = "reason", type = "text-single", "Reason", } |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
588 }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
589 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
590 local set_affiliation_handler = adhoc_simple(set_affiliation_layout, function (fields, errors) |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
591 if errors then |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
592 local errmsg = {}; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
593 for field, err in pairs(errors) do |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
594 errmsg[#errmsg + 1] = field .. ": " .. err; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
595 end |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
596 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
597 end |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
598 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
599 local room = get_room_from_jid(fields.room); |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
600 if not room then |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
601 return { status = "canceled", error = { message = "No such room"; }; }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
602 end |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
603 local ok, err, condition = room:set_affiliation(true, fields.jid, fields.affiliation, fields.reason); |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
604 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
605 if not ok then |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
606 return { status = "canceled", error = { message = "Affiliation change failed: "..err..":"..condition; }; }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
607 end |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
608 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
609 return { status = "completed", info = "Affiliation updated", |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
610 }; |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
611 end); |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
612 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
613 local set_affiliation_desc = adhoc_new("Set affiliation in room", |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
614 "http://prosody.im/protocol/muc#set-affiliation", set_affiliation_handler, "admin"); |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
615 |
|
e4034f6668a5
MUC: Add ad-hoc command setting affiliation in a room (fixes #1174)
Kim Alvefur <zash@zash.se>
parents:
10693
diff
changeset
|
616 module:provides("adhoc", set_affiliation_desc); |
|
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
617 end |
