mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
improve delete_subscriptions code
SVN Revision: 2903
This commit is contained in:
parent
0c9e0168d5
commit
13220d44f4
@ -390,35 +390,34 @@ unsubscribe_node(NodeId, Sender, Subscriber, SubId) ->
|
|||||||
end, SubState#pubsub_state.subscriptions),
|
end, SubState#pubsub_state.subscriptions),
|
||||||
case Sub of
|
case Sub of
|
||||||
{value, S} ->
|
{value, S} ->
|
||||||
delete_subscription(SubKey, NodeId, S, SubState),
|
delete_subscriptions(SubKey, NodeId, [S], SubState),
|
||||||
{result, default};
|
{result, default};
|
||||||
false ->
|
false ->
|
||||||
{error, ?ERR_EXTENDED('unexpected-request',
|
{error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")}
|
||||||
"not-subscribed")}
|
|
||||||
end;
|
end;
|
||||||
%% Asking to remove all subscriptions to the given node
|
%% Asking to remove all subscriptions to the given node
|
||||||
SubId == all ->
|
SubId == all ->
|
||||||
[delete_subscription(SubKey, NodeId, S, SubState) || S <- Subscriptions],
|
delete_subscriptions(SubKey, NodeId, Subscriptions, SubState),
|
||||||
{result, default};
|
{result, default};
|
||||||
%% No subid supplied, but there's only one matching
|
%% No subid supplied, but there's only one matching
|
||||||
%% subscription, so use that.
|
%% subscription, so use that.
|
||||||
length(Subscriptions) == 1 ->
|
length(Subscriptions) == 1 ->
|
||||||
delete_subscription(SubKey, NodeId, hd(Subscriptions), SubState),
|
delete_subscriptions(SubKey, NodeId, Subscriptions, SubState),
|
||||||
{result, default};
|
{result, default};
|
||||||
true ->
|
true ->
|
||||||
{error, ?ERR_EXTENDED('bad-request', "subid-required")}
|
{error, ?ERR_EXTENDED('bad-request', "subid-required")}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
delete_subscription(SubKey, NodeID, {Subscription, SubId}, SubState) ->
|
delete_subscriptions(SubKey, NodeId, Subscriptions, SubState) ->
|
||||||
Affiliation = SubState#pubsub_state.affiliation,
|
NewSubs = lists:foldl(fun({Subscription, SubId}, Acc) ->
|
||||||
AllSubs = SubState#pubsub_state.subscriptions,
|
pubsub_subscription:delete_subscription(SubKey, NodeId, SubId),
|
||||||
NewSubs = AllSubs -- [{Subscription, SubId}],
|
Acc -- [{Subscription, SubId}]
|
||||||
pubsub_subscription:unsubscribe_node(SubKey, NodeID, SubId),
|
end, SubState#pubsub_state.subscriptions, Subscriptions),
|
||||||
case {Affiliation, NewSubs} of
|
case {SubState#pubsub_state.affiliation, NewSubs} of
|
||||||
{none, []} ->
|
{none, []} ->
|
||||||
% Just a regular subscriber, and this is final item, so
|
% Just a regular subscriber, and this is final item, so
|
||||||
% delete the state.
|
% delete the state.
|
||||||
del_state(NodeID, SubKey);
|
del_state(NodeId, SubKey);
|
||||||
_ ->
|
_ ->
|
||||||
set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
set_state(SubState#pubsub_state{subscriptions = NewSubs})
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user