25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Fix updating pending subscriptions (EJAB-980)

SVN Revision: 2367
This commit is contained in:
Christophe Romain 2009-07-17 19:58:42 +00:00
parent 08a72c1693
commit 2729285977
2 changed files with 27 additions and 22 deletions

View File

@ -1416,18 +1416,11 @@ update_auth(Host, Node, Type, NodeId, Subscriber,
case Subscription of
[{pending, SubID}] -> %% TODO does not work if several pending
NewSubscription = case Allow of
true ->
node_call(Type, set_subscriptions,
[NodeId, Subscriber,
replace_subscription({subscribed, SubID},
Subscriptions)]),
{subscribed, SubID};
false ->
node_call(Type, unsubscribe_node,
[NodeId, Subscriber, Subscriber,
SubID]),
none
true -> subscribed;
false -> none
end,
node_call(Type, set_subscriptions,
[NodeId, Subscriber, NewSubscription, SubID]),
send_authorization_approval(Host, Subscriber, Node,
NewSubscription),
{result, ok};
@ -1435,17 +1428,6 @@ update_auth(Host, Node, Type, NodeId, Subscriber,
{error, ?ERR_UNEXPECTED_REQUEST}
end.
replace_subscription(NewSub, Subs) ->
lists:foldl(fun(S, A) -> replace_subscription_helper(NewSub, S, A) end,
[], Subs).
replace_subscription_helper({none, SubID}, {_, SubID}, Acc) ->
Acc;
replace_subscription_helper({NewSub, SubID}, {_, SubID}, Acc) ->
[{NewSub, SubID} | Acc];
replace_subscription_helper(_, OldSub, Acc) ->
[OldSub | Acc].
-define(XFIELD(Type, Label, Var, Val),
{xmlelement, "field", [{"type", Type},
{"label", translate:translate(Lang, Label)},

View File

@ -703,8 +703,31 @@ set_subscriptions(NodeId, Owner, none, SubId) ->
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")};
_ ->
unsub_with_subid(NodeId, SubId, SubState)
end;
set_subscriptions(NodeId, Owner, Subscription, SubId) ->
SubKey = jlib:jid_tolower(Owner),
SubState = get_state(NodeId, SubKey),
case {SubId, SubState#pubsub_state.subscriptions} of
{_, []} ->
{error, ?ERR_ITEM_NOT_FOUND};
{"", [{_, SID}]} ->
replace_subscription({Subscription, SID}, SubState);
{"", [_|_]} ->
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")};
_ ->
replace_subscription({Subscription, SubId}, SubState)
end.
replace_subscription(NewSub, SubState) ->
NewSubs = replace_subscription(NewSub,
SubState#pubsub_state.subscriptions, []),
set_state(SubState#pubsub_state{subscriptions = NewSubs}).
replace_subscription(_, [], Acc) ->
Acc;
replace_subscription({Sub, SubID}, [{_, SubID} | T], Acc) ->
replace_subscription({Sub, SubID}, T, [{Sub, SubID} | Acc]).
unsub_with_subid(NodeId, SubId, SubState) ->
pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid,
NodeId, SubId),