Software /
code /
prosody
Annotate
plugins/muc/mod_muc.lua @ 7370:0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 18 Apr 2016 19:18:37 +0200 |
parent | 7367:2aef5e8b69e9 |
child | 7371:d5ba0dec0c95 |
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 |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 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
|
10 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
|
11 end |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
13 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
|
14 room_mt = muclib.room_mt; -- Yes, global. |
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
|
15 |
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
16 local affiliation_notify = module:require "muc/affiliation_notify"; -- luacheck: ignore 211 |
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
|
17 |
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
18 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
|
19 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
|
20 room_mt.set_name = name.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
|
21 |
4caef6d53304
plugins/muc: Move loading of optional muc libraries from muc.lib.lua to mod_muc
daurnimator <quae@daurnimator.com>
parents:
6745
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 |
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 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 end |
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
|
35 |
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 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
|
37 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
|
38 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
|
39 |
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 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
|
41 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
|
42 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
|
43 |
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 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
|
45 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
|
46 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
|
47 |
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
|
48 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
|
49 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
|
50 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
|
51 |
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 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 |
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 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
|
60 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
|
61 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
|
62 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
|
63 |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 local um_is_admin = require "core.usermanager".is_admin; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 module:depends "muc_unique" |
6206
f937bb5c83c3
plugins/muc: Move locking to seperate module
daurnimator <quae@daurnimator.com>
parents:
6205
diff
changeset
|
74 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
|
75 |
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
|
76 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
|
77 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
|
78 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
|
79 |
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 end |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
86 |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
87 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
|
88 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
6745 | 89 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
|
90 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
|
91 end |
6742
6efeb801d62f
Backed out changeset bea3862b6bde in favor of a different approach
Kim Alvefur <zash@zash.se>
parents:
6741
diff
changeset
|
92 end |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
93 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
94 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
|
95 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
|
96 local room_configs = module:open_store("config"); |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
97 |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
98 local function room_save(room, forced) |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
99 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
|
100 local is_persistent = persistent.get(room); |
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
|
101 if is_persistent or forced 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
|
102 persistent_rooms:set(nil, 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
|
103 local data = room:freeze(forced); |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
104 return room_configs:set(node, data); |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
105 else |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
106 persistent_rooms:set(nil, 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
|
107 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
|
108 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
109 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
110 |
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
|
111 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, 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
|
112 module:log("debug", "%s evicted", 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
|
113 room_save(room, true); -- Force to disk |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
114 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
|
115 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
116 -- 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
|
117 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
|
118 local room = event.room |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
119 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
|
120 module:fire_event("muc-room-destroyed", { room = room }); |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
121 end |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
122 end); |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
123 |
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
|
124 function track_room(room) |
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 rooms:set(room.jid, room); |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
126 -- When room is created, over-ride 'save' method |
5210
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
127 room.save = room_save; |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
128 end |
862a6fae05e7
MUC: Expose create_room(jid).
Waqas Hussain <waqas20@gmail.com>
parents:
5195
diff
changeset
|
129 |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
130 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
|
131 local node = jid_split(jid); |
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5376
diff
changeset
|
132 local data = room_configs:get(node); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
133 if data then |
7367
2aef5e8b69e9
MUC: Move room deserialization to muc.lib
Kim Alvefur <zash@zash.se>
parents:
7361
diff
changeset
|
134 local room = muclib.restore_room(data); |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
135 track_room(room); |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
136 return room; |
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
137 end |
6205
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
138 end |
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
139 |
6348
bffc885dc378
mod_muc: Fix tracebacks (thanks nick1)
Kim Alvefur <zash@zash.se>
parents:
6334
diff
changeset
|
140 function forget_room(room) |
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
|
141 module:log("debug", "Forgetting %s", 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
|
142 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
|
143 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
|
144 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
|
145 |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
146 function 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
|
147 module:log("debug", "Deleting %s", 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
|
148 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
|
149 persistent_rooms:set(nil, 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
|
150 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
|
151 |
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 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
|
153 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
|
154 room:save(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
|
155 forget_room(room); |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
156 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
157 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
158 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
159 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
|
160 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
|
161 if room 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
|
162 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
|
163 return room; |
6333
93b8438fe761
plugins/muc/mod_muc: Use map store for room persistence
daurnimator <quae@daurnimator.com>
parents:
6332
diff
changeset
|
164 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
|
165 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
|
166 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
167 |
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
|
168 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
|
169 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
|
170 return rooms:values(); |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 end |
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
|
178 for room_jid in pairs(persistent_rooms_storage:get(nil) or {}) 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
|
179 if 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
|
180 local room = restore_room(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
|
181 if room == nil then |
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
|
182 module:log("error", "Missing data for room '%s', omitting from iteration", 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
|
183 else |
0ebc7ff1fff5
MUC: Switch to util.cache for storing rooms, store rooms to disk on eviction
Kim Alvefur <zash@zash.se>
parents:
7367
diff
changeset
|
184 coroutine.yield(room); |
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
|
185 end |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
186 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
187 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
|
188 end); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
189 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
191 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
|
192 local reply = event.reply; |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
193 module:log("debug", "host-disco-items called"); |
6245
8ec4ff630eb4
plugins/muc/mod_muc.lua: Add "each_room" function to iterate over rooms (instead of accessing directly)
daurnimator <quae@daurnimator.com>
parents:
6244
diff
changeset
|
194 for room in each_room() do |
5580
db5d1a350cc7
mod_muc: Refactor config form handling, and allow for clients to submit incomplete forms. Fixes #246
Matthew Wild <mwild1@gmail.com>
parents:
5577
diff
changeset
|
195 if not room:get_hidden() then |
6245
8ec4ff630eb4
plugins/muc/mod_muc.lua: Add "each_room" function to iterate over rooms (instead of accessing directly)
daurnimator <quae@daurnimator.com>
parents:
6244
diff
changeset
|
196 reply:tag("item", {jid=room.jid, name=room:get_name()}):up(); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
197 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
198 end |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
199 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
200 |
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
|
201 module:hook("muc-room-pre-create", function(event) |
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
|
202 track_room(event.room); |
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
|
203 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
|
204 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
210 |
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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 ) 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
|
225 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); |
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
|
226 return true; |
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
|
227 end |
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
|
228 end); |
4370 | 229 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
|
230 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
231 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
232 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
|
233 -- Normal room interactions |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
234 ["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
|
235 ["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
|
236 ["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
|
237 ["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
|
238 ["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
|
239 ["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
|
240 ["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
|
241 ["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
|
242 -- Host room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
243 ["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
|
244 ["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
|
245 ["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
|
246 ["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
|
247 ["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
|
248 ["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
|
249 ["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
|
250 ["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
|
251 -- 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
|
252 ["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
|
253 ["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
|
254 ["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
|
255 } do |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 -- 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
|
262 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
|
263 room = muclib.new_room(room_jid); |
7246
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
264 elseif stanza.attr.type ~= "error" 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
|
265 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); |
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
|
266 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
|
267 else |
80923a1a8fe1
MUC: Don't reply to error stanzas with more error stanzas (thanks woffs)
Kim Alvefur <zash@zash.se>
parents:
7086
diff
changeset
|
268 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
|
269 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
|
270 end |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
271 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
|
272 end, -2) |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
273 end |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
274 |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
275 function shutdown_component() |
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
276 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
277 :tag("status", { code = "332"}):up(); |
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
|
278 for room in each_room(true) do |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
279 room:clear(x); |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
280 end |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
281 end |
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
282 module:hook_global("server-stopping", shutdown_component); |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
283 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
284 do -- Ad-hoc commands |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
285 module:depends "adhoc"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
286 local t_concat = table.concat; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
287 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
|
288 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
|
289 local array = require "util.array"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
290 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
|
291 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
292 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
|
293 title = "Destroy rooms"; |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
294 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
|
295 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
296 { 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
|
297 { 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
|
298 }; |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
299 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
300 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
|
301 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
|
302 end, function(fields, errors) |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
303 if errors then |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
304 local errmsg = {}; |
7086
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
305 for field, err in pairs(errors) do |
6cc7c9da29ed
MUC: Rename variables to please luacheck
Kim Alvefur <zash@zash.se>
parents:
6800
diff
changeset
|
306 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
|
307 end |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
308 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
|
309 end |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
310 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
|
311 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
|
312 end |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
313 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
|
314 end); |
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
315 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
|
316 |
6247
851647eb6657
plugins/muc/mod_muc: Place adhoc section into own scope
daurnimator <quae@daurnimator.com>
parents:
6246
diff
changeset
|
317 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
|
318 end |