Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 6243:b7c95e9c13de
plugins/muc/mod_muc: Move `restrict_room_creation` into own area. now uses pre-create hook
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 29 Apr 2014 19:00:45 -0400 |
parent | 6241:6b4ff34dc8ea |
child | 6244:dfaacf042cfe |
comparison
equal
deleted
inserted
replaced
6242:67efeadd9e77 | 6243:b7c95e9c13de |
---|---|
8 | 8 |
9 local array = require "util.array"; | 9 local array = require "util.array"; |
10 | 10 |
11 if module:get_host_type() ~= "component" then | 11 if module:get_host_type() ~= "component" then |
12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); | 12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); |
13 end | |
14 | |
15 local restrict_room_creation = module:get_option("restrict_room_creation"); | |
16 if restrict_room_creation then | |
17 if restrict_room_creation == true then | |
18 restrict_room_creation = "admin"; | |
19 elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then | |
20 restrict_room_creation = nil; | |
21 end | |
22 end | 13 end |
23 | 14 |
24 local muclib = module:require "muc"; | 15 local muclib = module:require "muc"; |
25 local muc_new_room = muclib.new_room; | 16 local muc_new_room = muclib.new_room; |
26 room_mt = muclib.room_mt; -- Yes, global. | 17 room_mt = muclib.room_mt; -- Yes, global. |
144 module:hook("muc-room-destroyed",function(event) | 135 module:hook("muc-room-destroyed",function(event) |
145 local room = event.room | 136 local room = event.room |
146 forget_room(room.jid) | 137 forget_room(room.jid) |
147 end) | 138 end) |
148 | 139 |
140 do | |
141 local restrict_room_creation = module:get_option("restrict_room_creation"); | |
142 if restrict_room_creation == true then | |
143 restrict_room_creation = "admin"; | |
144 end | |
145 if restrict_room_creation then | |
146 local host_suffix = module.host:gsub("^[^%.]+%.", ""); | |
147 module:hook("muc-room-pre-create", function(event) | |
148 local user_jid = event.stanza.attr.from; | |
149 if not is_admin(user_jid) and not ( | |
150 restrict_room_creation == "local" and | |
151 select(2, jid_split(user_jid)) == host_suffix | |
152 ) then | |
153 origin.send(st.error_reply(stanza, "cancel", "not-allowed")); | |
154 return true; | |
155 end | |
156 end); | |
157 end | |
158 end | |
159 | |
149 -- Watch presence to create rooms | 160 -- Watch presence to create rooms |
150 local function attempt_room_creation(event) | 161 local function attempt_room_creation(event) |
151 local origin, stanza = event.origin, event.stanza; | 162 local origin, stanza = event.origin, event.stanza; |
152 local room_jid = jid_bare(stanza.attr.to); | 163 local room_jid = jid_bare(stanza.attr.to); |
153 if stanza.attr.type == nil and | 164 if stanza.attr.type == nil and get_room_from_jid(room_jid) == nil then |
154 get_room_from_jid(room_jid) == nil and | |
155 ( | |
156 not(restrict_room_creation) or | |
157 is_admin(stanza.attr.from) or | |
158 ( | |
159 restrict_room_creation == "local" and | |
160 select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "") | |
161 ) | |
162 ) then | |
163 create_room(room_jid); | 165 create_room(room_jid); |
164 end | 166 end |
165 end | 167 end |
166 module:hook("presence/full", attempt_room_creation, -1) | 168 module:hook("presence/full", attempt_room_creation, -1) |
167 module:hook("presence/bare", attempt_room_creation, -1) | 169 module:hook("presence/bare", attempt_room_creation, -1) |