{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
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);
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),