Changeset

174:f9aff1fc7e99

Inbound subscription request
author Waqas Hussain <waqas20@gmail.com>
date Sat, 25 Oct 2008 03:13:10 +0500
parents 173:f3a2af4d2ff2
children 175:5f71d290bb44
files core/rostermanager.lua core/stanza_router.lua
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/rostermanager.lua	Sat Oct 25 02:38:24 2008 +0500
+++ b/core/rostermanager.lua	Sat Oct 25 03:13:10 2008 +0500
@@ -135,4 +135,10 @@
 	end
 end
 
+function is_contact_subscribed(username, host, jid)
+	local roster = load_roster(username, host);
+	local item = roster[jid];
+	return item and (item.subscription == "from" or item.subscription == "both");
+end
+
 return _M;
\ No newline at end of file
--- a/core/stanza_router.lua	Sat Oct 25 02:38:24 2008 +0500
+++ b/core/stanza_router.lua	Sat Oct 25 03:13:10 2008 +0500
@@ -207,7 +207,16 @@
 								send(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"}));
 							end
 						elseif stanza.attr.type == "subscribe" then
-							-- TODO
+							if rostermanager.is_contact_subscribed(node, host, from_bare) then
+								send(origin, st.presence(from=to_bare, to=from_bare, type="subscribed")); -- already subscribed
+							else
+								local pres = st.presence({from=from_bare}, type="subscribe");
+								for k in pairs(user.sessions) do -- return presence for all resources
+									if user.sessions[k].presence then
+										send(user.sessions[k], pres);
+									end
+								end
+							end
 						elseif stanza.attr.type == "unsubscribe" then
 							if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then
 								rostermanager.roster_push(node, host, from_bare);