# HG changeset patch
# User Waqas Hussain <waqas20@gmail.com>
# Date 1259391546 -18000
# Node ID 67b64995ae1eb5f36c9b5d5aae7f94424e9fe6df
# Parent  22417227d2cecef4eef61109c7dc2efd445198ee
mod_register: Properly notify contacts of subscription removal on account deletion.

diff -r 22417227d2ce -r 67b64995ae1e plugins/mod_register.lua
--- a/plugins/mod_register.lua	Thu Nov 26 15:19:59 2009 +0500
+++ b/plugins/mod_register.lua	Sat Nov 28 11:59:06 2009 +0500
@@ -43,21 +43,21 @@
 					session:close({condition = "not-authorized", text = "Account deleted"});
 				end
 				-- TODO datamanager should be able to delete all user data itself
-				datamanager.store(username, host, "roster", nil);
 				datamanager.store(username, host, "vcard", nil);
 				datamanager.store(username, host, "private", nil);
 				datamanager.store(username, host, "offline", nil);
-				--local bare = username.."@"..host;
+				local bare = username.."@"..host;
 				for jid, item in pairs(roster) do
-					if jid ~= "pending" then
-						if item.subscription == "both" or item.subscription == "to" then
-							-- TODO unsubscribe
+					if jid and jid ~= "pending" then
+						if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then
+							core_post_stanza(hosts[host], st.presence({type="unsubscribed", from=bare, to=jid}));
 						end
-						if item.subscription == "both" or item.subscription == "from" then
-							-- TODO unsubscribe
+						if item.subscription == "both" or item.subscription == "to" or item.ask then
+							core_post_stanza(hosts[host], st.presence({type="unsubscribe", from=bare, to=jid}));
 						end
 					end
 				end
+				datamanager.store(username, host, "roster", nil);
 				datamanager.store(username, host, "accounts", nil); -- delete accounts datastore at the end
 				module:log("info", "User removed their account: %s@%s", username, host);
 				module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session });