aboutsummaryrefslogtreecommitdiff
path: root/src/mod_pubsub/mod_pubsub.erl
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2009-08-27 21:38:23 +0000
committerChristophe Romain <christophe.romain@process-one.net>2009-08-27 21:38:23 +0000
commit2fdabe8b5beb3e2d949cc9fa8e17d76225be35b9 (patch)
treecbdf706ca34e668b1b5cdce0fbaf1772bce65a4a /src/mod_pubsub/mod_pubsub.erl
parentFix EDoc comment (diff)
several improvements, and fix odbc subscriptions issues
SVN Revision: 2553
Diffstat (limited to 'src/mod_pubsub/mod_pubsub.erl')
-rw-r--r--src/mod_pubsub/mod_pubsub.erl107
1 files changed, 51 insertions, 56 deletions
diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
index 3469173fe..017a3d2fa 100644
--- a/src/mod_pubsub/mod_pubsub.erl
+++ b/src/mod_pubsub/mod_pubsub.erl
@@ -1409,7 +1409,11 @@ send_pending_auth_events(Host, Node, Owner) ->
true ->
case node_call(Type, get_affiliation, [NodeID, Owner]) of
{result, owner} ->
- broadcast_pending_auth_events(N),
+ {result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
+ lists:foreach(fun({J, pending, _SubID}) -> send_authorization_request(N, jlib:make_jid(J));
+ ({J, pending}) -> send_authorization_request(N, jlib:make_jid(J));
+ (_) -> ok
+ end, Subscriptions),
{result, ok};
_ ->
{error, ?ERR_FORBIDDEN}
@@ -1425,14 +1429,6 @@ send_pending_auth_events(Host, Node, Owner) ->
Err
end.
-broadcast_pending_auth_events(#pubsub_node{type = Type, id = NodeID} = Node) ->
- {result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
- lists:foreach(fun ({J, pending, _SubID}) ->
- send_authorization_request(Node, jlib:make_jid(J));
- ({J, pending}) ->
- send_authorization_request(Node, jlib:make_jid(J))
- end, Subscriptions).
-
%%% authorization handling
send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
@@ -1762,18 +1758,22 @@ delete_node(_Host, [], _Owner) ->
{error, ?ERR_NOT_ALLOWED};
delete_node(Host, Node, Owner) ->
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
- SubsByDepth = get_collection_subscriptions(Host, Node),
- case node_call(Type, get_affiliation, [NodeId, Owner]) of
- {result, owner} ->
- Removed = tree_call(Host, delete_node, [Host, Node]),
- case node_call(Type, delete_node, [Removed]) of
+ SubsByDepth = get_collection_subscriptions(Host, Node),
+ case node_call(Type, get_affiliation, [NodeId, Owner]) of
+ {result, owner} ->
+ SubsByDepth = case tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]) of
+ {result, T} -> [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- T];
+ _ -> []
+ end,
+ Removed = tree_call(Host, delete_node, [Host, Node]),
+ case node_call(Type, delete_node, [Removed]) of
{result, Res} -> {result, {SubsByDepth, Res}};
- Error -> Error
- end;
- _ ->
- %% Entity is not an owner
- {error, ?ERR_FORBIDDEN}
- end
+ Error -> Error
+ end;
+ _ ->
+ %% Entity is not an owner
+ {error, ?ERR_FORBIDDEN}
+ end
end,
Reply = [],
case transaction(Host, Node, Action, transaction) of
@@ -2959,24 +2959,28 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
end.
get_collection_subscriptions(Host, Node) ->
- lists:map(fun ({Depth, Nodes}) ->
- {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
- end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
+ Action = fun() ->
+ {result, lists:map(fun({Depth, Nodes}) ->
+ {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
+ end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
+ end,
+ case transaction(Action, sync_dirty) of
+ {result, CollSubs} -> CollSubs;
+ _ -> []
+ end.
get_node_subs(#pubsub_node{type = Type,
- nodeid = {Host, Node},
id = NodeID}) ->
- case node_action(Host, Type, get_node_subscriptions, [NodeID]) of
- {result, Subs} ->
- get_options_for_subs(Host, Node, NodeID, Subs);
- Other ->
- Other
+ case node_call(Type, get_node_subscriptions, [NodeID]) of
+ {result, Subs} -> get_options_for_subs(NodeID, Subs);
+ Other -> Other
end.
-get_options_for_subs(_Host, Node, NodeID, Subs) ->
+get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
- case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
- {result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
+ case pubsub_subscription:read_subscription(JID, NodeID, SubID) of
+ {error, notfound} -> [{JID, SubID, []} | Acc];
+ #pubsub_subscription{options = Options} -> [{JID, SubID, Options} | Acc];
_ -> Acc
end;
(_, Acc) ->
@@ -3006,8 +3010,7 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
From = service_jid(Host),
%% Handles explicit subscriptions
- FilteredSubsByDepth = depths_to_deliver(NotifyType, SubsByDepth),
- NodesByJID = collate_subs_by_jid(FilteredSubsByDepth),
+ NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
lists:foreach(fun ({LJID, Nodes}) ->
LJIDs = case BroadcastAll of
true ->
@@ -3068,36 +3071,28 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
ok
end.
-depths_to_deliver(NotifyType, SubsByDepth) ->
- NodesToDeliver =
- fun (Depth, Node, Subs, Acc) ->
- lists:foldl(fun ({LJID, _Node, SubOptions} = S, Acc2) ->
+subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
+ NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
+ NodeId = case Node#pubsub_node.nodeid of
+ {_, N} -> N;
+ Other -> Other
+ end,
+ NodeOptions = Node#pubsub_node.options,
+ lists:foldl(fun({LJID, _SubID, SubOptions}, Acc2) ->
case is_to_deliver(LJID, NotifyType, Depth,
- Node#pubsub_node.options,
- SubOptions) of
- true -> [S | Acc2];
+ NodeOptions, SubOptions) of
+ true -> [{LJID, NodeId}|Acc2];
false -> Acc2
end
end, Acc, Subs)
end,
-
- DepthsToDeliver =
- fun ({Depth, SubsByNode}, Acc) ->
- lists:foldl(fun ({Node, Subs}, Acc2) ->
+ DepthsToDeliver = fun({Depth, SubsByNode}, Acc) ->
+ lists:foldl(fun({Node, Subs}, Acc2) ->
NodesToDeliver(Depth, Node, Subs, Acc2)
end, Acc, SubsByNode)
end,
-
- lists:foldl(DepthsToDeliver, [], SubsByDepth).
-
-collate_subs_by_jid(SubsByDepth) ->
- lists:foldl(fun ({JID, Node, _Options}, Acc) ->
- OldNodes = case lists:keysearch(JID, 1, Acc) of
- {value, {JID, Nodes}} -> Nodes;
- false -> []
- end,
- lists:keystore(JID, 1, Acc, {JID, [Node | OldNodes]})
- end, [], SubsByDepth).
+ JIDSubs = lists:foldl(DepthsToDeliver, [], SubsByDepth),
+ [{LJID, proplists:append_values(LJID, JIDSubs)} || LJID <- proplists:get_keys(JIDSubs)].
%% If we don't know the resource, just pick first if any
%% If no resource available, check if caps anyway (remote online)