From ca403c25e77184a3aeeccd23c139ebb05fe3fe6b Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Mon, 24 Aug 2009 22:40:40 +0000 Subject: [PATCH] fix manage subscriptions owner's usecase SVN Revision: 2528 --- src/mod_pubsub/mod_pubsub.erl | 27 +++++++++++++++++---------- src/mod_pubsub/node_hometree.erl | 11 ++++++++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 7135bdb37..6fea31d0d 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -2669,16 +2669,23 @@ set_subscriptions(Host, Node, From, EntitiesEls) -> {error, ?ERR_BAD_REQUEST}; _ -> Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) -> - case lists:member(Owner, Owners) of - true -> - lists:foreach(fun({JID, Subscription, SubId}) -> - node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) - end, Entities), - {result, []}; - _ -> - {error, ?ERR_FORBIDDEN} - end - end, + case lists:member(Owner, Owners) of + true -> + Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> + + case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of + {error, Err} -> [{error, Err} | Acc]; + _ -> Acc + end + end, [], Entities), + case Result of + [] -> {result, []}; + _ -> {error, ?ERR_NOT_ACCEPTABLE} + end; + _ -> + {error, ?ERR_FORBIDDEN} + end + end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; Other -> Other diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl index 6484fbe0a..cb7373677 100644 --- a/src/mod_pubsub/node_hometree.erl +++ b/src/mod_pubsub/node_hometree.erl @@ -701,7 +701,10 @@ set_subscriptions(NodeId, Owner, Subscription, SubId) -> SubState = get_state(NodeId, SubKey), case {SubId, SubState#pubsub_state.subscriptions} of {_, []} -> - {error, ?ERR_ITEM_NOT_FOUND}; + case Subscription of + none -> ok; + _ -> new_subscription(NodeId, Owner, Subscription, SubState) + end; {"", [{_, SID}]} -> case Subscription of none -> unsub_with_subid(NodeId, SID, SubState); @@ -726,6 +729,12 @@ replace_subscription(_, [], Acc) -> replace_subscription({Sub, SubId}, [{_, SubID} | T], Acc) -> replace_subscription({Sub, SubId}, T, [{Sub, SubID} | Acc]). +new_subscription(NodeId, Owner, Subscription, SubState) -> + SubId = pubsub_subscription:add_subscription(Owner, NodeId, []), + Subscriptions = SubState#pubsub_state.subscriptions, + set_state(SubState#pubsub_state{subscriptions = [{Subscription, SubId} | Subscriptions]}), + {Subscription, SubId}. + unsub_with_subid(NodeId, SubId, SubState) -> pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid, NodeId, SubId),