Software /
code /
prosody
Annotate
plugins/muc/mod_muc.lua @ 6245:8ec4ff630eb4
plugins/muc/mod_muc.lua: Add "each_room" function to iterate over rooms (instead of accessing directly)
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Wed, 30 Apr 2014 13:12:32 -0400 |
parent | 6244:dfaacf042cfe |
child | 6246:45b8ad2b14c5 |
rev | line source |
---|---|
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2033
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2033
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5692
diff
changeset
|
4 -- |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 -- |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
5807
d7212bd61b60
mod_muc: Import util.array
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
9 local array = require "util.array"; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 if module:get_host_type() ~= "component" then |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 end |
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
15 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
|
16 room_mt = muclib.room_mt; -- Yes, global. |
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
|
17 local iterators = require "util.iterators"; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 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
|
19 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
|
20 local st = require "util.stanza"; |
2033
38d32c154cec
MUC: Added config option 'restrict_room_creation' to allow restricting room creation to admins.
Waqas Hussain <waqas20@gmail.com>
parents:
2028
diff
changeset
|
21 local um_is_admin = require "core.usermanager".is_admin; |
5376
ba9be0be4bbb
MUC: Access prosody.hosts instead of the old global hosts
Kim Alvefur <zash@zash.se>
parents:
5335
diff
changeset
|
22 local hosts = prosody.hosts; |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
24 local rooms = module:shared "rooms"; |
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
25 _G.rooms = rooms; |
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
|
26 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 module:depends "muc_unique" |
6206
f937bb5c83c3
plugins/muc: Move locking to seperate module
daurnimator <quae@daurnimator.com>
parents:
6205
diff
changeset
|
31 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
|
32 |
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
|
33 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
|
34 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
|
35 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
|
36 |
6234
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 end |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
43 |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
44 local _set_affiliation = room_mt.set_affiliation; |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
45 function room_mt:set_affiliation(actor, jid, ...) |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
46 if is_admin(jid) then return nil, "modify", "not-acceptable"; end |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
47 return _set_affiliation(self, actor, jid, ...); |
cc8a6ca2d7c5
plugins/muc/mod_muc: Move affiliation monkey patch into own scope
daurnimator <quae@daurnimator.com>
parents:
6222
diff
changeset
|
48 end |
5064
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
49 end |
7a1eb302c562
MUC: Give host and server admins "owner" affiliation in all rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
5062
diff
changeset
|
50 |
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
|
51 function track_room(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
|
52 rooms[room.jid] = room; |
6205
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
53 end |
49dd381666f3
plugins/muc/mod_muc: Move room locking into hook
daurnimator <quae@daurnimator.com>
parents:
6179
diff
changeset
|
54 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
55 function forget_room(jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
56 rooms[jid] = nil; |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
57 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
58 |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
59 function get_room_from_jid(room_jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
60 return rooms[room_jid] |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
61 end |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
62 |
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
|
63 function each_room() |
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
|
64 return iterators.values(rooms); |
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
|
65 end |
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
|
66 |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
67 do -- Persistent rooms |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
68 local persistent = module:require "muc/persistent"; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
69 local persistent_rooms_storage = module:open_store("persistent"); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
70 local persistent_rooms = persistent_rooms_storage:get() or {}; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
71 local room_configs = module:open_store("config"); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
72 |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
73 local function room_save(room, forced) |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
74 local node = jid_split(room.jid); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
75 local is_persistent = persistent.get(room); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
76 persistent_rooms[room.jid] = is_persistent; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
77 if is_persistent then |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
78 local history = room._data.history; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
79 room._data.history = nil; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
80 local data = { |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
81 jid = room.jid; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
82 _data = room._data; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
83 _affiliations = room._affiliations; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
84 }; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
85 room_configs:set(node, data); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
86 room._data.history = history; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
87 elseif forced then |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
88 room_configs:set(node, nil); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
89 if not next(room._occupants) then -- Room empty |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
90 rooms[room.jid] = nil; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
91 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
92 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
93 if forced then persistent_rooms_storage:set(nil, persistent_rooms); end |
4924
d8b9fe5900a2
MUC: Handle missing persistent room data.
Waqas Hussain <waqas20@gmail.com>
parents:
4528
diff
changeset
|
94 end |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
95 |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
96 -- When room is created, over-ride 'save' method |
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
|
97 module:hook("muc-occupant-pre-create", function(event) |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
98 event.room.save = room_save; |
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
|
99 end, 1000); |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
100 |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
101 -- Automatically destroy empty non-persistent rooms |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
102 module:hook("muc-occupant-left",function(event) |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
103 local room = event.room |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
104 if not room:has_occupant() and not persistent.get(room) then -- empty, non-persistent room |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
105 module:fire_event("muc-room-destroyed", { room = room }); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
106 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
107 end); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
108 |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
109 local persistent_errors = false; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
110 for jid in pairs(persistent_rooms) do |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
111 local node = jid_split(jid); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
112 local data = room_configs:get(node); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
113 if data 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
|
114 local room = muclib.new_room(jid); |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
115 room._data = data._data; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
116 room._affiliations = data._affiliations; |
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
|
117 track_room(room); |
6238
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
118 else -- missing room data |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
119 persistent_rooms[jid] = nil; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
120 module:log("error", "Missing data for room '%s', removing from persistent room list", jid); |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
121 persistent_errors = true; |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
122 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
123 end |
b2b523d21891
plugins/muc/mod_muc: Move room persistence to own block
daurnimator <quae@daurnimator.com>
parents:
6237
diff
changeset
|
124 if persistent_errors then persistent_rooms_storage:set(nil, persistent_rooms); end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
125 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1748
diff
changeset
|
126 |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
127 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
|
128 local reply = event.reply; |
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 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
|
133 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 end |
5691
18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
Florian Zeitz <florob@babelmonkeys.de>
parents:
5659
diff
changeset
|
135 end); |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 |
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
|
137 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
|
138 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
|
139 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
|
140 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
141 module:hook("muc-room-destroyed",function(event) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
142 local room = event.room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
143 forget_room(room.jid) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
144 end) |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
145 |
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
|
146 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
|
147 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
|
148 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
|
149 restrict_room_creation = "admin"; |
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
|
150 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
|
151 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
|
152 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
|
153 module:hook("muc-room-pre-create", function(event) |
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
|
154 local user_jid = event.stanza.attr.from; |
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
|
155 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
|
156 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
|
157 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
|
158 ) 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
166 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
|
167 -- Normal room interactions |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
168 ["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
|
169 ["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
|
170 ["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
|
171 ["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
|
172 ["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
|
173 ["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
|
174 ["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
|
175 ["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
|
176 -- Host room |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
177 ["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
|
178 ["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
|
179 ["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
|
180 ["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
|
181 ["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
|
182 ["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
|
183 ["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
|
184 ["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
|
185 -- 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
|
186 ["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
|
187 ["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
|
188 ["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
|
189 } do |
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 -- 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
|
196 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
|
197 room = muclib.new_room(room_jid); |
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
|
198 else |
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
|
199 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
|
200 return true; |
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 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
|
202 end |
6109
566aba0482b6
plugins/muc/mod_muc: Refactor to use new methods available
daurnimator <quae@daurnimator.com>
parents:
6091
diff
changeset
|
203 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
|
204 end, -2) |
3560
fb49b63e3fe2
MUC: Use events for hooking stanzas instead of the component stanza handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3510
diff
changeset
|
205 end |
6091
3a1c39b31497
plugins/muc/mod_muc: Move Xep-0307 MUC unique to seperate file
daurnimator <quae@daurnimator.com>
parents:
6000
diff
changeset
|
206 |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
207 function shutdown_component() |
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
208 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
|
209 :tag("status", { code = "332"}):up(); |
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
|
210 for room in each_room() do |
6241
6b4ff34dc8ea
plugins/muc/mod_muc: Use module:shared instead of save/restore
daurnimator <quae@daurnimator.com>
parents:
6240
diff
changeset
|
211 room:clear(x); |
1747
28e5f6b535a8
MUC: Added support for reloading MUC library code.
Waqas Hussain <waqas20@gmail.com>
parents:
1741
diff
changeset
|
212 end |
1738
ee4a7151ed07
MUC: New basic mod_muc based on the new MUC library
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
213 end |
5062
88e198d65905
MUC: Send unavailable presence when the component or server is shutting down.
Waqas Hussain <waqas20@gmail.com>
parents:
5058
diff
changeset
|
214 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
|
215 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
216 -- Ad-hoc commands |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
217 module:depends("adhoc") |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
218 local t_concat = table.concat; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
219 local adhoc_new = module:require "adhoc".new; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
220 local adhoc_initial = require "util.adhoc".new_initial_data_form; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
221 local dataforms_new = require "util.dataforms".new; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
222 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
223 local destroy_rooms_layout = dataforms_new { |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
224 title = "Destroy rooms"; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
225 instructions = "Select the rooms to destroy"; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
226 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
227 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
228 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"}; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
229 }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
230 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
231 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() |
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
|
232 return { rooms = array.collect(each_room):pluck("jid"):sort(); }; |
5692
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
233 end, function(fields, errors) |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
234 if errors then |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
235 local errmsg = {}; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
236 for name, err in pairs(errors) do |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
237 errmsg[#errmsg + 1] = name .. ": " .. err; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
238 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
239 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
240 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
241 for _, room in ipairs(fields.rooms) do |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
242 rooms[room]:destroy(); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
243 rooms[room] = nil; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
244 end |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
245 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") }; |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
246 end); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
247 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
248 |
24e7e58155d8
mod_muc: Add Ad-Hoc command to destroy MUC rooms
Florian Zeitz <florob@babelmonkeys.de>
parents:
5691
diff
changeset
|
249 module:provides("adhoc", destroy_rooms_desc); |