Software /
code /
prosody-modules
Comparison
mod_poke_strangers/mod_poke_strangers.lua @ 2045:0aa8aa6cdb1b
mod_poke_strangers: Create only one hook, re-use the UUIDs.
author | Thijs Alkemade <me@thijsalkema.de> |
---|---|
date | Fri, 05 Feb 2016 11:37:47 +0100 |
parent | 2044:06faf7a149e3 |
child | 5852:1e28f32257d6 |
comparison
equal
deleted
inserted
replaced
2044:06faf7a149e3 | 2045:0aa8aa6cdb1b |
---|---|
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | 4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
5 local uuid_generate = require "util.uuid".generate; | 5 local uuid_generate = require "util.uuid".generate; |
6 local set = require "util.set"; | 6 local set = require "util.set"; |
7 | 7 |
8 local recently_queried = set.new(); | 8 local recently_queried = set.new(); |
9 | |
10 local version_id = uuid_generate(); | |
11 local disco_id = uuid_generate(); | |
12 | |
13 module:hook("iq-result/host/" .. version_id, function (event) | |
14 module:log("info", "Stranger " .. event.stanza.attr.from .. " version: " .. tostring(event.stanza)); | |
15 return true; | |
16 end); | |
17 | |
18 module:hook("iq-result/host/" .. disco_id, function (event) | |
19 module:log("info", "Stranger " .. event.stanza.attr.from .. " disco: " .. tostring(event.stanza)); | |
20 return true; | |
21 end); | |
9 | 22 |
10 function check_subscribed(event) | 23 function check_subscribed(event) |
11 local stanza = event.stanza; | 24 local stanza = event.stanza; |
12 local local_user_jid = stanza.attr.to; | 25 local local_user_jid = stanza.attr.to; |
13 local to_user, to_host, to_resource = jid_split(local_user_jid); | 26 local to_user, to_host, to_resource = jid_split(local_user_jid); |
25 return nil; | 38 return nil; |
26 end | 39 end |
27 | 40 |
28 recently_queried:add(stranger_jid); | 41 recently_queried:add(stranger_jid); |
29 | 42 |
30 local version_id = uuid_generate(); | |
31 | |
32 module:hook("iq-result/host/" .. version_id, function (event) | |
33 module:log("info", "Stranger " .. stranger_jid .. " version: " .. tostring(event.stanza)); | |
34 return true; | |
35 end); | |
36 | |
37 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = version_id }):query("jabber:iq:version")); | 43 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = version_id }):query("jabber:iq:version")); |
38 | |
39 | |
40 local disco_id = uuid_generate(); | |
41 | |
42 module:hook("iq-result/host/" .. disco_id, function (event) | |
43 module:log("info", "Stranger " .. stranger_jid .. " disco: " .. tostring(event.stanza)); | |
44 return true; | |
45 end); | |
46 | 44 |
47 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = disco_id }):query("http://jabber.org/protocol/disco#info")); | 45 module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = disco_id }):query("http://jabber.org/protocol/disco#info")); |
48 end | 46 end |
49 | 47 |
50 return nil; | 48 return nil; |