aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2010-01-14 12:51:22 +0000
committerChristophe Romain <christophe.romain@process-one.net>2010-01-14 12:51:22 +0000
commit7aff5defac46b27d53707abaf1413e4eedb2c5a1 (patch)
tree5b70fb3b757a94a74ec6bdf8e767958d2f1f26e7 /src
parentadd send_loop robustness (diff)
improve delete_subscriptions code
SVN Revision: 2902
Diffstat (limited to 'src')
-rw-r--r--src/mod_pubsub/node_hometree.erl27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl
index c84f4875c..740b2f5ff 100644
--- a/src/mod_pubsub/node_hometree.erl
+++ b/src/mod_pubsub/node_hometree.erl
@@ -389,41 +389,38 @@ unsubscribe_node(NodeId, Sender, Subscriber, SubId) ->
end, SubState#pubsub_state.subscriptions),
case Sub of
{value, S} ->
- delete_subscription(SubKey, NodeId, S, SubState),
+ delete_subscriptions(SubKey, NodeId, [S], SubState),
{result, default};
false ->
- {error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST,
- "not-subscribed")}
+ {error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")}
end;
%% Asking to remove all subscriptions to the given node
SubId == all ->
- [delete_subscription(SubKey, NodeId, S, SubState) || S <- Subscriptions],
+ delete_subscriptions(SubKey, NodeId, Subscriptions, SubState),
{result, default};
- %% No subid supplied, but there's only one matching
- %% subscription, so use that.
+ %% No subid supplied, but there's only one matching subscription
length(Subscriptions) == 1 ->
- delete_subscription(SubKey, NodeId, hd(Subscriptions), SubState),
+ delete_subscriptions(SubKey, NodeId, Subscriptions, SubState),
{result, default};
%% No subid and more than one possible subscription match.
true ->
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")}
end.
-delete_subscription(SubKey, NodeID, {Subscription, SubId}, SubState) ->
- Affiliation = SubState#pubsub_state.affiliation,
- AllSubs = SubState#pubsub_state.subscriptions,
- NewSubs = AllSubs -- [{Subscription, SubId}],
- pubsub_subscription:delete_subscription(SubKey, NodeID, SubId),
- case {Affiliation, NewSubs} of
+delete_subscriptions(SubKey, NodeId, Subscriptions, SubState) ->
+ NewSubs = lists:foldl(fun({Subscription, SubId}, Acc) ->
+ pubsub_subscription:delete_subscription(SubKey, NodeId, SubId),
+ Acc -- [{Subscription, SubId}]
+ end, SubState#pubsub_state.subscriptions, Subscriptions),
+ case {SubState#pubsub_state.affiliation, NewSubs} of
{none, []} ->
% Just a regular subscriber, and this is final item, so
% delete the state.
- del_state(NodeID, SubKey);
+ del_state(NodeId, SubKey);
_ ->
set_state(SubState#pubsub_state{subscriptions = NewSubs})
end.
-
%% @spec (NodeId, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
%% {true, PubsubItem} | {result, Reply}
%% NodeId = mod_pubsub:pubsubNodeId()