Software /
code /
prosody
Comparison
plugins/muc/mod_muc.lua @ 5691:18a115beeebe
mod_muc: Utilize mod_disco, instead of reimplementing disco handling
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Wed, 05 Jun 2013 00:04:44 +0200 |
parent | 5659:9f9de8078164 |
child | 5692:24e7e58155d8 |
comparison
equal
deleted
inserted
replaced
5690:630e7224a65f | 5691:18a115beeebe |
---|---|
37 local persistent_rooms = persistent_rooms_storage:get() or {}; | 37 local persistent_rooms = persistent_rooms_storage:get() or {}; |
38 local room_configs = module:open_store("config"); | 38 local room_configs = module:open_store("config"); |
39 | 39 |
40 -- Configurable options | 40 -- Configurable options |
41 muclib.set_max_history_length(module:get_option_number("max_history_messages")); | 41 muclib.set_max_history_length(module:get_option_number("max_history_messages")); |
42 | |
43 module:depends("disco"); | |
44 module:add_identity("conference", "text", muc_name); | |
45 module:add_feature("http://jabber.org/protocol/muc"); | |
42 | 46 |
43 local function is_admin(jid) | 47 local function is_admin(jid) |
44 return um_is_admin(jid, module.host); | 48 return um_is_admin(jid, module.host); |
45 end | 49 end |
46 | 50 |
105 | 109 |
106 local host_room = muc_new_room(muc_host); | 110 local host_room = muc_new_room(muc_host); |
107 host_room.route_stanza = room_route_stanza; | 111 host_room.route_stanza = room_route_stanza; |
108 host_room.save = room_save; | 112 host_room.save = room_save; |
109 | 113 |
110 local function get_disco_info(stanza) | 114 module:hook("host-disco-items", function(event) |
111 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") | 115 local reply = event.reply; |
112 :tag("identity", {category='conference', type='text', name=muc_name}):up() | 116 module:log("debug", "host-disco-items called"); |
113 :tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply | |
114 end | |
115 local function get_disco_items(stanza) | |
116 local reply = st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); | |
117 for jid, room in pairs(rooms) do | 117 for jid, room in pairs(rooms) do |
118 if not room:get_hidden() then | 118 if not room:get_hidden() then |
119 reply:tag("item", {jid=jid, name=room:get_name()}):up(); | 119 reply:tag("item", {jid=jid, name=room:get_name()}):up(); |
120 end | 120 end |
121 end | 121 end |
122 return reply; -- TODO cache disco reply | 122 end); |
123 end | |
124 | 123 |
125 local function handle_to_domain(event) | 124 local function handle_to_domain(event) |
126 local origin, stanza = event.origin, event.stanza; | 125 local origin, stanza = event.origin, event.stanza; |
127 local type = stanza.attr.type; | 126 local type = stanza.attr.type; |
128 if type == "error" or type == "result" then return; end | 127 if type == "error" or type == "result" then return; end |
129 if stanza.name == "iq" and type == "get" then | 128 if stanza.name == "iq" and type == "get" then |
130 local xmlns = stanza.tags[1].attr.xmlns; | 129 local xmlns = stanza.tags[1].attr.xmlns; |
131 local node = stanza.tags[1].attr.node; | 130 local node = stanza.tags[1].attr.node; |
132 if xmlns == "http://jabber.org/protocol/disco#info" and not node then | 131 if xmlns == "http://jabber.org/protocol/muc#unique" then |
133 origin.send(get_disco_info(stanza)); | |
134 elseif xmlns == "http://jabber.org/protocol/disco#items" and not node then | |
135 origin.send(get_disco_items(stanza)); | |
136 elseif xmlns == "http://jabber.org/protocol/muc#unique" then | |
137 origin.send(st.reply(stanza):tag("unique", {xmlns = xmlns}):text(uuid_gen())); -- FIXME Random UUIDs can theoretically have collisions | 132 origin.send(st.reply(stanza):tag("unique", {xmlns = xmlns}):text(uuid_gen())); -- FIXME Random UUIDs can theoretically have collisions |
138 else | 133 else |
139 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- TODO disco/etc | 134 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- TODO disco/etc |
140 end | 135 end |
141 else | 136 else |