Software /
code /
prosody
Annotate
plugins/muc/mod_muc.lua @ 8944:200ec7d38a0e
MUC: Remove affiliation notify support, nothing uses it
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 27 Jun 2018 16:00:54 +0100 |
parent | 8926:89f6b2a2bec3 |
child | 8976:92f0876b9230 |
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 |
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
16 -- each_room(local_only) -> () -> room |
ce1737520943
MUC: Write down which functions are exposed and thus available to other modules
Kim Alvefur <zash@zash.se>
parents:
8387
diff
changeset
|
17 -- shutdown_component() |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 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
|
20 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
|
21 end |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 |
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 |
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
|
31 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
|
32 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
|
33 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
|
34 |
8833
9c90cd2fc4c3
MUC: Add support for setting a room language (closes #1149)
Kim Alvefur <zash@zash.se>
parents:
8818
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 |
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
|
49 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
|
50 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
|
51 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
|
52 |
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 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
|
54 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
|
55 room_mt.set_members_only = members_only.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
|
56 |
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 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
|
58 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
|
59 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
|
60 |
8865
2a8bbfcb6868
MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents:
8843
diff
changeset
|
61 local request = module:require "muc/request"; |
2a8bbfcb6868
MUC: Move voice request into its own lib
Kim Alvefur <zash@zash.se>
parents:
8843
diff
changeset
|
62 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
|
63 |
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
|
64 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
|
65 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
|
66 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
|
67 |
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 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 |
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 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
|
76 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
|
77 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
|
78 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
|
79 |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 local jid_split = require "util.jid".split; |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
81 local jid_bare = require "util.jid".bare; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 local st = require "util.stanza"; |
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
|
83 local cache = require "util.cache"; |
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
|
84 local um_is_admin = require "core.usermanager".is_admin; |
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
|
85 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 module:depends "muc_unique" |
6206
f937bb5c83c3
plugins/muc: Move locking to seperate module
daurnimator <quae@daurnimator.com>
parents:
6205
diff
changeset
|
90 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
|
91 |
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
|
92 local function is_admin(jid) |
3388
02e668d64e05
MUC: No need to call is_admin twice now, global admins are admins on hosts
Matthew Wild <mwild1@gmail.com>
parents:
3330
diff
changeset
|
93 return um_is_admin(jid, module.host); |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
94 end |
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
95 |
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
96 do -- Monkey patch to make server admins room owners |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
97 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
|
98 function room_mt:get_affiliation(jid) |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
99 if is_admin(jid) then return "owner"; end |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
100 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
|
101 end |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
102 |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
103 local _set_affiliation = room_mt.set_affiliation; |
6768
7816923fd5bf
mod_muc: Fix a traceback when an owner joins a room
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6745
diff
changeset
|
104 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
6745 | 105 if affiliation ~= "owner" and is_admin(jid) then return nil, "modify", "not-acceptable"; end |
6768
7816923fd5bf
mod_muc: Fix a traceback when an owner joins a room
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6745
diff
changeset
|
106 return _set_affiliation(self, actor, jid, affiliation, reason); |
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
107 end |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
108 end |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
109 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
110 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
|
111 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
|
112 local room_configs = module:open_store("config"); |
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
113 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
|
114 |
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
115 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
|
116 |
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
117 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
|
118 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
|
119 local is_persistent = persistent.get(room); |
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
120 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; |
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
121 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
|
122 persistent_rooms:set(nil, room.jid, true); |
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
123 local data, state = room:freeze(savestate); |
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 persistent_rooms:set(nil, room.jid, nil); |
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
128 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
|
129 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
|
130 end |
6742
6efeb801d62f
Backed out changeset bea3862b6bde in favor of a different approach
Kim Alvefur <zash@zash.se>
parents:
6741
diff
changeset
|
131 end |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
132 |
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
|
133 local max_rooms = module:get_option_number("muc_max_rooms"); |
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
134 local max_live_rooms = module:get_option_number("muc_room_cache_size", 100); |
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
135 |
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
136 local room_hit = module:measure("room_hit", "rate"); |
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 if max_rooms then |
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
141 module:log("info", "Room limit of %d reached, no new rooms allowed"); |
c96c00dc424b
MUC: Add support for an optional hard limit on number of rooms (fixes #766)
Kim Alvefur <zash@zash.se>
parents:
8707
diff
changeset
|
142 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
|
143 end |
8385 | 144 module:log("debug", "Evicting room %s", jid); |
8925
d367aeb9c50f
MUC: Rename eviction hit rate measure
Kim Alvefur <zash@zash.se>
parents:
8879
diff
changeset
|
145 room_eviction(); |
8387
7d61431e1aa6
MUC: Cache names of public rooms on eviction
Kim Alvefur <zash@zash.se>
parents:
8386
diff
changeset
|
146 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; |
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
147 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
|
148 if not ok then |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
149 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
|
150 return false; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
151 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
|
152 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
|
153 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
154 -- 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
|
155 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
|
156 local room = event.room |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
157 if not room:has_occupant() and not persistent.get(room) then -- empty, non-persistent room |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
158 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
|
159 end |
7417
4c8ee8175f5e
MUC: Lower priority of hook so plugins hooks run before
Kim Alvefur <zash@zash.se>
parents:
7415
diff
changeset
|
160 end, -1); |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
161 |
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
|
162 function track_room(room) |
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
163 if rooms:set(room.jid, room) then |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
164 -- 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
|
165 room.save = room_save; |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
166 return room; |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
167 end |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
168 return false; |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
169 end |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
170 |
8661
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
171 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
|
172 module:log("debug", "Returning error from broken room %s", room.jid); |
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
173 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); |
7fc0784491ef
MUC: Override methods on broken rooms to return internal-server-error instead
Kim Alvefur <zash@zash.se>
parents:
8660
diff
changeset
|
174 return true; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
175 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
176 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
177 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
|
178 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
|
179 local data, err = room_configs:get(node); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
180 if data then |
8178
9f2a5fc9e4a5
MUC: Log debug message when restoring a room from storage
Kim Alvefur <zash@zash.se>
parents:
8026
diff
changeset
|
181 module:log("debug", "Restoring room %s from storage", jid); |
8659
4006755c1097
MUC: Log failure to load room state
Kim Alvefur <zash@zash.se>
parents:
8658
diff
changeset
|
182 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
|
183 if not state and s_err then |
4006755c1097
MUC: Log failure to load room state
Kim Alvefur <zash@zash.se>
parents:
8658
diff
changeset
|
184 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
|
185 end |
7415
cbb05b454c13
MUC: Separate config from live state
Kim Alvefur <zash@zash.se>
parents:
7414
diff
changeset
|
186 local room = muclib.restore_room(data, state); |
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
187 return track_room(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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
195 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
196 |
6348
bffc885dc378
mod_muc: Fix tracebacks (thanks nick1)
Kim Alvefur <zash@zash.se>
parents:
6334
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
203 function delete_room(room) |
7650
4c2407422f71
Logging error if MUC room cache is full
Sam Whited <sam@samwhited.com>
parents:
7641
diff
changeset
|
204 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
|
205 room_configs:set(jid_split(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
|
206 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
|
207 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
|
208 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
|
209 |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
210 function module.unload() |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
211 for room in rooms:values() do |
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
212 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
|
213 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
|
214 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
215 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
216 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
217 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
|
218 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
|
219 if room then |
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
220 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
|
221 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
|
222 return room; |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
223 end |
8926
89f6b2a2bec3
MUC: Measure cache hits and misses
Kim Alvefur <zash@zash.se>
parents:
8925
diff
changeset
|
224 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
|
225 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
|
226 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
227 |
8875
be3230b42f12
MUC: Allow passing config to public create_room API
Kim Alvefur <zash@zash.se>
parents:
8870
diff
changeset
|
228 function create_room(room_jid, config) |
7641
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 end |
8875
be3230b42f12
MUC: Allow passing config to public create_room API
Kim Alvefur <zash@zash.se>
parents:
8870
diff
changeset
|
233 local room = muclib.new_room(room_jid, config); |
7641
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
234 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
|
235 room = room; |
5eef792bb2e1
MUC: Restore modern version of public create_room() function removed in dfaacf042cfe
Kim Alvefur <zash@zash.se>
parents:
7536
diff
changeset
|
236 }); |
8877
9182398c64b9
MUC: Track rooms created via internal public API
Kim Alvefur <zash@zash.se>
parents:
8875
diff
changeset
|
237 return track_room(room); |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
238 end |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
239 |
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
|
240 function each_room(local_only) |
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
|
241 if local_only then |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
242 return rooms:values(); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
243 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
|
244 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
|
245 local seen = {}; -- Don't iterate over persistent rooms twice |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
246 for room in rooms:values() do |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 local room = restore_room(room_jid); |
8657
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
261 if room then |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
262 coroutine.yield(room); |
a804f2e75f10
MUC: Prevent room eviction on storage failure
Kim Alvefur <zash@zash.se>
parents:
8656
diff
changeset
|
263 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
|
264 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
|
265 end |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
266 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
267 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
|
268 end); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
269 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
270 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
271 module:hook("host-disco-items", function(event) |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
272 local reply = event.reply; |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
273 module:log("debug", "host-disco-items called"); |
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
274 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
|
275 for jid, room_name in pairs(room_items_cache) do |
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
276 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
|
277 end |
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
278 else |
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
279 for room in each_room() do |
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
280 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
|
281 local jid, room_name = room.jid, room:get_name(); |
7404
57ca4dcd91a7
MUC: Use correct room name variable, fixes traceback (thanks mathieui)
Kim Alvefur <zash@zash.se>
parents:
7403
diff
changeset
|
282 room_items_cache[jid] = room_name; |
7371
d5ba0dec0c95
MUC: Cache public rooms and their names to speed up disco#items
Kim Alvefur <zash@zash.se>
parents:
7370
diff
changeset
|
283 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
|
284 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
285 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
286 end |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
287 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
288 |
8867
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
289 module:hook("muc-room-pre-create", function (event) |
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
290 local room = event.room; |
8870 | 291 room:set_public(module:get_option_boolean("muc_room_default_public", false)); |
292 room:set_persistent(module:get_option_boolean("muc_room_default_persistent", room:get_persistent())); | |
293 room:set_members_only(module:get_option_boolean("muc_room_default_members_only", room:get_members_only())); | |
294 room:set_moderated(module:get_option_boolean("muc_room_default_moderated", room:get_moderated())); | |
295 room:set_whois(module:get_option_boolean("muc_room_default_public_jids", room:get_whois() == "anyone") and "anyone" or "moderators"); | |
296 room:set_changesubject(module:get_option_boolean("muc_room_default_change_subject", room:get_changesubject())); | |
8867
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
297 room:set_historylength(module:get_option_number("muc_room_default_history_length", room:get_historylength())); |
8868
b9e56f46916e
MUC: Use xml:lang from stanza that creates a room as default for language
Kim Alvefur <zash@zash.se>
parents:
8867
diff
changeset
|
298 room:set_language(event.stanza.attr["xml:lang"] or module:get_option_string("muc_room_default_language")); |
8867
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
299 end, 1); |
c601c834bf01
MUC: Add support for setting MUC room defaults from the config file
Kim Alvefur <zash@zash.se>
parents:
8865
diff
changeset
|
300 |
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
|
301 module:hook("muc-room-pre-create", function(event) |
4370 | 302 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
|
303 if not track_room(event.room) then |
3b54f8472b51
MUC: Return error if unable to keep track of room due to storage failure
Kim Alvefur <zash@zash.se>
parents:
8659
diff
changeset
|
304 origin.send(st.error_reply(stanza, "wait", "resource-constraint")); |
3b54f8472b51
MUC: Return error if unable to keep track of room due to storage failure
Kim Alvefur <zash@zash.se>
parents:
8659
diff
changeset
|
305 return true; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
306 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
|
307 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
|
308 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
314 |
6243
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
315 do |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
316 local restrict_room_creation = module:get_option("restrict_room_creation"); |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
317 if restrict_room_creation == true then |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
318 restrict_room_creation = "admin"; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
319 end |
6243
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
320 if restrict_room_creation then |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
321 local host_suffix = module.host:gsub("^[^%.]+%.", ""); |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
322 module:hook("muc-room-pre-create", function(event) |
6328
93fb28851d9e
mod_muc: Fix use of undefined global. Fixes #431.
Matthew Wild <mwild1@gmail.com>
parents:
6276
diff
changeset
|
323 local origin, stanza = event.origin, event.stanza; |
93fb28851d9e
mod_muc: Fix use of undefined global. Fixes #431.
Matthew Wild <mwild1@gmail.com>
parents:
6276
diff
changeset
|
324 local user_jid = stanza.attr.from; |
6243
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
325 if not is_admin(user_jid) and not ( |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
326 restrict_room_creation == "local" and |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
327 select(2, jid_split(user_jid)) == host_suffix |
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
328 ) then |
8180
67a9ff352271
MUC: Include a human-readable message when denying room creation because of restrict_room_creation
Kim Alvefur <zash@zash.se>
parents:
8179
diff
changeset
|
329 origin.send(st.error_reply(stanza, "cancel", "not-allowed", "Room creation is restricted")); |
6243
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
330 return true; |
8705
1d66f66a13c9
MUC: Don't reply to errors with more errors (fixes #1122)
Kim Alvefur <zash@zash.se>
parents:
8704
diff
changeset
|
331 end |
6243
b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
daurnimator <quae@daurnimator.com>
parents:
6241
diff
changeset
|
332 end); |
4370 | 333 end |
1780
668ce0a2050d
MUC: Added a send() method to the component. Fixes issues with local mod_vcard.
Waqas Hussain <waqas20@gmail.com>
parents:
1767
diff
changeset
|
334 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
335 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
336 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
|
337 -- Normal room interactions |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
338 ["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
|
339 ["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
|
340 ["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
|
341 ["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
|
342 ["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
|
343 ["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
|
344 ["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
|
345 ["presence/bare"] = "handle_presence_to_room" ; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
346 -- Host room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
347 ["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
|
348 ["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
|
349 ["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
|
350 ["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
|
351 ["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
|
352 ["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
|
353 ["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
|
354 ["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
|
355 -- 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
|
356 ["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
|
357 ["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
|
358 ["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
|
359 } do |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 local room = get_room_from_jid(room_jid); |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
364 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
|
365 -- Watch presence to create rooms |
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
|
366 if stanza.attr.type == nil and stanza.name == "presence" then |
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
|
367 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
|
368 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
|
369 elseif stanza.attr.type ~= "error" then |
8179
c5fa7fe3fd79
MUC: Return item-not-found for eg messages to non-existant rooms (changed in 566aba0482b6 for unknown reason)
Kim Alvefur <zash@zash.se>
parents:
8178
diff
changeset
|
370 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
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
|
371 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
|
372 else |
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
373 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
|
374 end |
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
|
375 end |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
376 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
|
377 end, -2) |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
378 end |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
379 |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
380 function shutdown_component() |
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
|
381 for room in each_room(true) do |
7414
1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
Kim Alvefur <zash@zash.se>
parents:
7411
diff
changeset
|
382 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
|
383 end |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
384 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
|
385 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
|
386 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
387 do -- Ad-hoc commands |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
388 module:depends "adhoc"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
389 local t_concat = table.concat; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
390 local adhoc_new = module:require "adhoc".new; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
391 local adhoc_initial = require "util.adhoc".new_initial_data_form; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
392 local array = require "util.array"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
393 local dataforms_new = require "util.dataforms".new; |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
394 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
395 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
|
396 title = "Destroy rooms"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
397 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
|
398 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
399 { 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
|
400 { 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
|
401 }; |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
402 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
403 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() |
6372
305226a9e581
mod_muc: Fix 'destroy rooms' adhoc command (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
6348
diff
changeset
|
404 return { rooms = array.collect(each_room()):pluck("jid"):sort(); }; |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
405 end, function(fields, errors) |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
406 if errors then |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
407 local errmsg = {}; |
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
408 for field, err in pairs(errors) do |
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
409 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
|
410 end |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
411 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
|
412 end |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
413 for _, room in ipairs(fields.rooms) do |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
414 get_room_from_jid(room):destroy(); |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
415 end |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
416 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") }; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
417 end); |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
418 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "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
|
419 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
420 module:provides("adhoc", destroy_rooms_desc); |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
421 end |