Changeset

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
parents 2044:06faf7a149e3
children 2046:980e5f5bd62c
files mod_poke_strangers/mod_poke_strangers.lua
diffstat 1 files changed, 13 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mod_poke_strangers/mod_poke_strangers.lua	Fri Feb 05 11:23:13 2016 +0100
+++ b/mod_poke_strangers/mod_poke_strangers.lua	Fri Feb 05 11:37:47 2016 +0100
@@ -7,6 +7,19 @@
 
 local recently_queried = set.new();
 
+local version_id = uuid_generate();
+local disco_id = uuid_generate();
+
+module:hook("iq-result/host/" .. version_id, function (event)
+	module:log("info", "Stranger " .. event.stanza.attr.from .. " version: " .. tostring(event.stanza));
+	return true;
+end);
+
+module:hook("iq-result/host/" .. disco_id, function (event)
+	module:log("info", "Stranger " .. event.stanza.attr.from .. " disco: " .. tostring(event.stanza));
+	return true;
+end);
+
 function check_subscribed(event)
 	local stanza = event.stanza;
 	local local_user_jid = stanza.attr.to;
@@ -27,23 +40,8 @@
 
 		recently_queried:add(stranger_jid);
 
-		local version_id = uuid_generate();
-
-		module:hook("iq-result/host/" .. version_id, function (event)
-			module:log("info", "Stranger " .. stranger_jid .. " version: " .. tostring(event.stanza));
-			return true;
-		end);
-
 		module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = version_id }):query("jabber:iq:version"));
 
-
-		local disco_id = uuid_generate();
-
-		module:hook("iq-result/host/" .. disco_id, function (event)
-			module:log("info", "Stranger " .. stranger_jid .. " disco: " .. tostring(event.stanza));
-			return true;
-		end);
-
 		module:send(st.iq({ type = "get", to = stranger_jid, from = to_host, id = disco_id }):query("http://jabber.org/protocol/disco#info"));
 	end