Changeset

3791:04c7b71ce078

mod_pep: Optimised PEP requests for disco info on caps change (issue #150).
author Waqas Hussain <waqas20@gmail.com>
date Sun, 28 Nov 2010 07:43:19 +0500
parents 3790:23cd998c765b
children 3792:1f9ab0fa77cc
files plugins/mod_pep.lua
diffstat 1 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pep.lua	Sat Nov 27 22:02:30 2010 +0000
+++ b/plugins/mod_pep.lua	Sun Nov 28 07:43:19 2010 +0500
@@ -117,9 +117,10 @@
 	local origin, stanza = event.origin, event.stanza;
 	local user = stanza.attr.to or (origin.username..'@'..origin.host);
 	local t = stanza.attr.type;
+	local self = not stanza.attr.to;
 
 	if not t then -- available presence
-		if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then
+		if self or subscription_presence(user, stanza.attr.from) then
 			local recipient = stanza.attr.from;
 			local current = recipients[user] and recipients[user][recipient];
 			local hash = get_caps_hash_from_presence(stanza, current);
@@ -133,10 +134,12 @@
 					publish_all(user, recipient, origin);
 				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")
-					);
+					if self or origin.type ~= "c2s" then
+						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
@@ -214,6 +217,7 @@
 		local disco = stanza.tags[1];
 		if disco and disco.name == "query" and disco.attr.xmlns == "http://jabber.org/protocol/disco#info" then
 			-- Process disco response
+			local self = not stanza.attr.to;
 			local user = stanza.attr.to or (session.username..'@'..session.host);
 			local contact = stanza.attr.from;
 			local current = recipients[user] and recipients[user][contact];
@@ -230,7 +234,16 @@
 				end
 			end
 			hash_map[ver] = notify; -- update hash map
-			recipients[user][contact] = notify; -- set recipient's data to calculated data
+			if self then
+				for jid, item in pairs(origin.roster) do -- for all interested contacts
+					if item.subscription == "both" or item.subscription == "from" then
+						if not recipients[jid] then recipients[jid] = {}; end
+						recipients[jid][contact] = notify;
+					end
+				end
+			else
+				recipients[user][contact] = notify; -- set recipient's data to calculated data
+			end
 			-- send messages to recipient
 			publish_all(user, contact, session);
 		end