X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_pep.lua;h=4a8300f1d0fc8600bc7021b54658ddff63b25ac6;hb=ee9546db04f34dc740b5b2b74ac269918ab9de9f;hp=3d0b6ad847953e1157e8399feb0dfa51d4f5cc95;hpb=1f79b420926685af6e7e46279c936b041a3e9ffe;p=prosody.git diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index 3d0b6ad8..4a8300f1 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -33,8 +33,10 @@ local function publish(session, node, item) -- store for the future local user_data = data[bare]; if disable then - if user_data then user_data[node] = nil; end - if not next(user_data) then data[bare] = nil; end + if user_data then + user_data[node] = nil; + if not next(user_data) then data[bare] = nil; end + end else if not user_data then user_data = {}; data[bare] = user_data; end user_data[node] = stanza; @@ -48,6 +50,18 @@ local function publish(session, node, item) 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 +99,16 @@ module:hook("presence/bare", function(event) 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 +199,7 @@ module:hook("iq/bare/disco", function(event) 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);