# HG changeset patch # User Waqas Hussain # Date 1246207771 -18000 # Node ID f989608964eca2202f867de12a3a549d1d38588d # Parent f02a5a982facc8be8b79cda08172faa6fe15fd91 mod_pep: Use cached caps diff -r f02a5a982fac -r f989608964ec plugins/mod_pep.lua --- a/plugins/mod_pep.lua Sun Jun 28 21:32:19 2009 +0500 +++ b/plugins/mod_pep.lua Sun Jun 28 21:49:31 2009 +0500 @@ -48,6 +48,18 @@ end end end +local function publish_all(user, recipient, session) + local d = data[user]; + local notify = recipients[user] and recipients[user][recipient]; + if d and notify then + for node, message in pairs(notify) do + if d[node] then + message.attr.to = recipient; + session.send(message); + end + end + end +end local function get_caps_hash_from_presence(stanza, current) local t = stanza.attr.type; @@ -85,11 +97,16 @@ if recipients[user] then recipients[user][recipient] = nil; end else recipients[user] = recipients[user] or {}; - recipients[user][recipient] = hash; - origin.send( - st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) - :query("http://jabber.org/protocol/disco#info") - ); + if hash_map[hash] then + recipients[user][recipient] = hash_map[hash]; + publish_all(user, recipient); + else + recipients[user][recipient] = hash; + origin.send( + st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) + :query("http://jabber.org/protocol/disco#info") + ); + end end end end, 10); @@ -180,15 +197,7 @@ hash_map[ver] = notify; -- update hash map recipients[user][contact] = notify; -- set recipient's data to calculated data -- send messages to recipient - local d = data[user]; - if d then - for node, message in pairs(notify) do - if d[node] then - message.attr.to = stanza.attr.from; - session.send(message); - end - end - end + publish_all(user, contact, session); end end end);