aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2012-08-01 01:36:16 +0500
committerWaqas Hussain <waqas20@gmail.com>2012-08-01 01:36:16 +0500
commit955e1b6695b36d49db0e6919aec6cd10d89d75ef (patch)
tree540c7d9ca85d20a292f43edd46511b373fc7da81
parentd4b224bc0ae49c721391f2256396480bb2cc1566 (diff)
downloadprosody-955e1b6695b36d49db0e6919aec6cd10d89d75ef.tar.gz
prosody-955e1b6695b36d49db0e6919aec6cd10d89d75ef.zip
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
-rw-r--r--core/rostermanager.lua14
-rw-r--r--plugins/mod_presence.lua17
2 files changed, 18 insertions, 13 deletions
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index ac4f4e3d..fdb890f9 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -278,23 +278,21 @@ function unsubscribed(username, host, jid)
local roster = load_roster(username, host);
local item = roster[jid];
local pending = is_contact_pending_in(username, host, jid);
- local changed = nil;
- if is_contact_pending_in(username, host, jid) then
+ if pending then
roster.pending[jid] = nil; -- TODO maybe delete roster.pending if empty?
- changed = true;
end
+ local subscribed;
if item then
if item.subscription == "from" then
item.subscription = "none";
- changed = true;
+ subscribed = true;
elseif item.subscription == "both" then
item.subscription = "to";
- changed = true;
+ subscribed = true;
end
end
- if changed then
- return save_roster(username, host, roster);
- end
+ local success = (pending or subscribed) and save_roster(username, host, roster);
+ return success, pending, subscribed;
end
function process_outbound_subscription_request(username, host, jid)
diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua
index dac86ae6..077bc31f 100644
--- a/plugins/mod_presence.lua
+++ b/plugins/mod_presence.lua
@@ -198,12 +198,19 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_
core_post_stanza(origin, stanza);
send_presence_of_available_resources(node, host, to_bare, origin);
elseif stanza.attr.type == "unsubscribed" then
- -- 1. route stanza
- -- 2. roster push (subscription = none or to)
- if rostermanager.unsubscribed(node, host, to_bare) then
- rostermanager.roster_push(node, host, to_bare);
+ -- 1. send unavailable
+ -- 2. route stanza
+ -- 3. roster push (subscription = from or both)
+ local success, pending_in, subscribed = rostermanager.unsubscribed(node, host, to_bare);
+ if success then
+ if subscribed then
+ rostermanager.roster_push(node, host, to_bare);
+ end
+ core_post_stanza(origin, stanza);
+ if subscribed then
+ send_presence_of_available_resources(node, host, to_bare, origin, st.presence({ type = "unavailable" }));
+ end
end
- core_post_stanza(origin, stanza);
else
origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid presence type"));
end