mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Fix updating pending subscriptions (EJAB-980)
SVN Revision: 2367
This commit is contained in:
parent
08a72c1693
commit
2729285977
@ -1416,18 +1416,11 @@ update_auth(Host, Node, Type, NodeId, Subscriber,
|
|||||||
case Subscription of
|
case Subscription of
|
||||||
[{pending, SubID}] -> %% TODO does not work if several pending
|
[{pending, SubID}] -> %% TODO does not work if several pending
|
||||||
NewSubscription = case Allow of
|
NewSubscription = case Allow of
|
||||||
true ->
|
true -> subscribed;
|
||||||
node_call(Type, set_subscriptions,
|
false -> none
|
||||||
[NodeId, Subscriber,
|
|
||||||
replace_subscription({subscribed, SubID},
|
|
||||||
Subscriptions)]),
|
|
||||||
{subscribed, SubID};
|
|
||||||
false ->
|
|
||||||
node_call(Type, unsubscribe_node,
|
|
||||||
[NodeId, Subscriber, Subscriber,
|
|
||||||
SubID]),
|
|
||||||
none
|
|
||||||
end,
|
end,
|
||||||
|
node_call(Type, set_subscriptions,
|
||||||
|
[NodeId, Subscriber, NewSubscription, SubID]),
|
||||||
send_authorization_approval(Host, Subscriber, Node,
|
send_authorization_approval(Host, Subscriber, Node,
|
||||||
NewSubscription),
|
NewSubscription),
|
||||||
{result, ok};
|
{result, ok};
|
||||||
@ -1435,17 +1428,6 @@ update_auth(Host, Node, Type, NodeId, Subscriber,
|
|||||||
{error, ?ERR_UNEXPECTED_REQUEST}
|
{error, ?ERR_UNEXPECTED_REQUEST}
|
||||||
end.
|
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),
|
-define(XFIELD(Type, Label, Var, Val),
|
||||||
{xmlelement, "field", [{"type", Type},
|
{xmlelement, "field", [{"type", Type},
|
||||||
{"label", translate:translate(Lang, Label)},
|
{"label", translate:translate(Lang, Label)},
|
||||||
|
@ -703,8 +703,31 @@ set_subscriptions(NodeId, Owner, none, SubId) ->
|
|||||||
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")};
|
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")};
|
||||||
_ ->
|
_ ->
|
||||||
unsub_with_subid(NodeId, SubId, SubState)
|
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.
|
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) ->
|
unsub_with_subid(NodeId, SubId, SubState) ->
|
||||||
pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid,
|
pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid,
|
||||||
NodeId, SubId),
|
NodeId, SubId),
|
||||||
|
Loading…
Reference in New Issue
Block a user