Mercurial > prosody-hg
comparison plugins/muc/mod_muc.lua @ 3560:fb49b63e3fe2
MUC: Use events for hooking stanzas instead of the component stanza handler.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Thu, 04 Nov 2010 19:38:05 +0500 |
| parents | 711eb5bf94b4 |
| children | bc3dfc00da5d |
comparison
equal
deleted
inserted
replaced
| 3559:0708d42ef0d4 | 3560:fb49b63e3fe2 |
|---|---|
| 111 host_room:handle_stanza(origin, stanza); | 111 host_room:handle_stanza(origin, stanza); |
| 112 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); | 112 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
| 113 end | 113 end |
| 114 end | 114 end |
| 115 | 115 |
| 116 component = register_component(muc_host, function(origin, stanza) | 116 function stanza_handler(event) |
| 117 local origin, stanza = event.origin, event.stanza; | |
| 117 local to_node, to_host, to_resource = jid_split(stanza.attr.to); | 118 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
| 118 if to_node then | 119 if to_node then |
| 119 local bare = to_node.."@"..to_host; | 120 local bare = to_node.."@"..to_host; |
| 120 if to_host == muc_host or bare == muc_host then | 121 if to_host == muc_host or bare == muc_host then |
| 121 local room = rooms[bare]; | 122 local room = rooms[bare]; |
| 140 else --[[not for us?]] end | 141 else --[[not for us?]] end |
| 141 return; | 142 return; |
| 142 end | 143 end |
| 143 -- to the main muc domain | 144 -- to the main muc domain |
| 144 handle_to_domain(origin, stanza); | 145 handle_to_domain(origin, stanza); |
| 145 end); | 146 end |
| 147 module:hook("iq/bare", stanza_handler); | |
| 148 module:hook("message/bare", stanza_handler); | |
| 149 module:hook("presence/bare", stanza_handler); | |
| 150 module:hook("iq/full", stanza_handler); | |
| 151 module:hook("message/full", stanza_handler); | |
| 152 module:hook("presence/full", stanza_handler); | |
| 153 module:hook("iq/host", stanza_handler); | |
| 154 module:hook("message/host", stanza_handler); | |
| 155 module:hook("presence/host", stanza_handler); | |
| 156 | |
| 157 component = register_component(muc_host, function() end); | |
| 146 function component.send(stanza) -- FIXME do a generic fix | 158 function component.send(stanza) -- FIXME do a generic fix |
| 147 if stanza.attr.type == "result" or stanza.attr.type == "error" then | 159 if stanza.attr.type == "result" or stanza.attr.type == "error" then |
| 148 core_post_stanza(component, stanza); | 160 core_post_stanza(component, stanza); |
| 149 else error("component.send only supports result and error stanzas at the moment"); end | 161 else error("component.send only supports result and error stanzas at the moment"); end |
| 150 end | 162 end |
