Changeset

172:71247788c7c7

Inbound subscription cancellation
author Waqas Hussain <waqas20@gmail.com>
date Sat, 25 Oct 2008 02:29:58 +0500
parents 171:28f420d057a0
children 173:f3a2af4d2ff2
files core/rostermanager.lua core/stanza_router.lua
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/core/rostermanager.lua	Sat Oct 25 02:16:29 2008 +0500
+++ b/core/rostermanager.lua	Sat Oct 25 02:29:58 2008 +0500
@@ -107,4 +107,18 @@
 	end
 end
 
+function process_inbound_subscription_cancellation(username, host, jid)
+	local roster = load_roster(username, host);
+	local item = roster[jid];
+	if item and (item.subscription == "to" or item.subscription == "both") then
+		if item.subscription == "to" then
+			item.subscription = "none";
+		else
+			item.subscription = "from";
+		end
+		-- FIXME do we need to item.ask = nil;?
+		return datamanager.store(username, host, "roster", roster);
+	end
+end
+
 return _M;
\ No newline at end of file
--- a/core/stanza_router.lua	Sat Oct 25 02:16:29 2008 +0500
+++ b/core/stanza_router.lua	Sat Oct 25 02:29:58 2008 +0500
@@ -211,7 +211,6 @@
 						elseif stanza.attr.type == "unsubscribe" then
 							-- TODO
 						elseif stanza.attr.type == "subscribed" then
-							-- TODO
 							if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
 								rostermanager.roster_push(node, host, from_bare);
 								for k in pairs(user.sessions) do -- return presence for all resources
@@ -226,7 +225,9 @@
 								pres.attr.from = nil;
 							end
 						elseif stanza.attr.type == "unsubscribed" then
-							-- TODO
+							if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then
+								rostermanager.roster_push(node, host, from_bare);
+							end
 						end -- discard any other type
 					else -- sender is available or unavailable
 						for k in pairs(user.sessions) do -- presence broadcast to all user resources