25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-10-19 15:32:08 +02:00

send created node notifications (EJAB-1225)

This commit is contained in:
Christophe Romain 2010-05-28 13:27:28 +02:00
parent e042fdb111
commit 0232f5958f
3 changed files with 83 additions and 67 deletions

View File

@ -1804,11 +1804,19 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
end, end,
case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of
{result, true} -> {result, true} ->
ParentTree = tree_call(Host, get_parentnodes_tree, [Host, Node, Owner]),
SubsByDepth = [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- ParentTree],
case tree_call(Host, create_node, [Host, Node, Type, Owner, NodeOptions, Parents]) of case tree_call(Host, create_node, [Host, Node, Type, Owner, NodeOptions, Parents]) of
{ok, NodeId} -> {ok, NodeId} ->
node_call(Type, create_node, [NodeId, Owner]); case node_call(Type, create_node, [NodeId, Owner]) of
{result, Result} -> {result, {NodeId, SubsByDepth, Result}};
Error -> Error
end;
{error, {virtual, NodeId}} -> {error, {virtual, NodeId}} ->
node_call(Type, create_node, [NodeId, Owner]); case node_call(Type, create_node, [NodeId, Owner]) of
{result, Result} -> {result, {NodeId, SubsByDepth, Result}};
Error -> Error
end;
Error -> Error ->
Error Error
end; end;
@ -1819,20 +1827,15 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
case transaction(CreateNode, transaction) of case transaction(CreateNode, transaction) of
{result, {Result, broadcast}} -> {result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
%%Lang = "en", %% TODO: fix broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
%%broadcast_publish_item(Host, Node, uniqid(), Owner,
%% [{xmlelement, "x", [{"xmlns", ?NS_DATA_FORMS}, {"type", "result"}],
%% [?XFIELD("hidden", "", "FORM_TYPE", ?NS_PUBSUB_NMI),
%% ?XFIELD("jid-single", "Node Creator", "creator", jlib:jid_to_string(OwnerKey))]}]),
case Result of case Result of
default -> {result, Reply}; default -> {result, Reply};
_ -> {result, Result} _ -> {result, Result}
end; end;
{result, default} -> {result, {_NodeId, _SubsByDepth, default}} ->
{result, Reply}; {result, Reply};
{result, Result} -> {result, {_NodeId, _SubsByDepth, Result}} ->
{result, Result}; {result, Result};
Error -> Error ->
%% in case we change transaction to sync_dirty... %% in case we change transaction to sync_dirty...
@ -3062,7 +3065,6 @@ broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, From,
case get_collection_subscriptions(Host, Node) of case get_collection_subscriptions(Host, Node) of
[] -> [] ->
{result, false}; {result, false};
SubsByDepth when is_list(SubsByDepth) -> SubsByDepth when is_list(SubsByDepth) ->
Content = case get_option(Options, deliver_payloads) of Content = case get_option(Options, deliver_payloads) of
true -> Payload; true -> Payload;
@ -3100,9 +3102,8 @@ broadcast_retract_items(Host, Node, NodeId, Type, NodeOptions, ItemIds, ForceNot
case (get_option(NodeOptions, notify_retract) or ForceNotify) of case (get_option(NodeOptions, notify_retract) or ForceNotify) of
true -> true ->
case get_collection_subscriptions(Host, Node) of case get_collection_subscriptions(Host, Node) of
[] -> [] ->
{result, false}; {result, false};
SubsByDepth when is_list(SubsByDepth)-> SubsByDepth when is_list(SubsByDepth)->
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
@ -3152,6 +3153,13 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) ->
{result, false} {result, false}
end. end.
broadcast_created_node(_, _, _, _, _, []) ->
{result, false};
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) ->
Stanza = event_stanza([#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'create', attrs = nodeAttr(Node)}]),
broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, true),
{result, true}.
broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
%broadcast(Host, Node, NodeId, NodeOptions, notify_config, false, 'items', ConfigEls) %broadcast(Host, Node, NodeId, NodeOptions, notify_config, false, 'items', ConfigEls)
case get_option(NodeOptions, notify_config) of case get_option(NodeOptions, notify_config) of

View File

@ -1619,11 +1619,19 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
end, end,
case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of
{result, true} -> {result, true} ->
ParentTree = tree_call(Host, get_parentnodes_tree, [Host, Node, Owner]),
SubsByDepth = [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- ParentTree],
case tree_call(Host, create_node, [Host, Node, Type, Owner, NodeOptions, Parents]) of case tree_call(Host, create_node, [Host, Node, Type, Owner, NodeOptions, Parents]) of
{ok, NodeId} -> {ok, NodeId} ->
node_call(Type, create_node, [NodeId, Owner]); case node_call(Type, create_node, [NodeId, Owner]) of
{result, Result} -> {result, {NodeId, SubsByDepth, Result}};
Error -> Error
end;
{error, {virtual, NodeId}} -> {error, {virtual, NodeId}} ->
node_call(Type, create_node, [NodeId, Owner]); case node_call(Type, create_node, [NodeId, Owner]) of
{result, Result} -> {result, {NodeId, SubsByDepth, Result}};
Error -> Error
end;
Error -> Error ->
Error Error
end; end;
@ -1634,20 +1642,15 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
case transaction(Host, CreateNode, transaction) of case transaction(Host, CreateNode, transaction) of
{result, {Result, broadcast}} -> {result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
%%Lang = "en", %% TODO: fix broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
%%broadcast_publish_item(Host, Node, uniqid(), Owner,
%% [{xmlelement, "x", [{"xmlns", ?NS_DATA_FORMS}, {"type", "result"}],
%% [?XFIELD("hidden", "", "FORM_TYPE", ?NS_PUBSUB_NMI),
%% ?XFIELD("jid-single", "Node Creator", "creator", jlib:jid_to_string(OwnerKey))]}]),
case Result of case Result of
default -> {result, Reply}; default -> {result, Reply};
_ -> {result, Result} _ -> {result, Result}
end; end;
{result, default} -> {result, {_NodeId, _SubsByDepth, default}} ->
{result, Reply}; {result, Reply};
{result, Result} -> {result, {_NodeId, _SubsByDepth, Result}} ->
{result, Result}; {result, Result};
Error -> Error ->
%% in case we change transaction to sync_dirty... %% in case we change transaction to sync_dirty...
@ -2878,7 +2881,6 @@ broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, From,
case get_collection_subscriptions(Host, Node) of case get_collection_subscriptions(Host, Node) of
[] -> [] ->
{result, false}; {result, false};
SubsByDepth when is_list(SubsByDepth) -> SubsByDepth when is_list(SubsByDepth) ->
Content = case get_option(Options, deliver_payloads) of Content = case get_option(Options, deliver_payloads) of
true -> Payload; true -> Payload;
@ -2916,9 +2918,8 @@ broadcast_retract_items(Host, Node, NodeId, Type, NodeOptions, ItemIds, ForceNot
case (get_option(NodeOptions, notify_retract) or ForceNotify) of case (get_option(NodeOptions, notify_retract) or ForceNotify) of
true -> true ->
case get_collection_subscriptions(Host, Node) of case get_collection_subscriptions(Host, Node) of
[] -> [] ->
{result, false}; {result, false};
SubsByDepth when is_list(SubsByDepth)-> SubsByDepth when is_list(SubsByDepth)->
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
@ -2968,6 +2969,13 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) ->
{result, false} {result, false}
end. end.
broadcast_created_node(_, _, _, _, _, []) ->
{result, false};
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) ->
Stanza = event_stanza([#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'create', attrs = nodeAttr(Node)}]),
broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, true),
{result, true}.
broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
%broadcast(Host, Node, NodeId, NodeOptions, notify_config, false, 'items', ConfigEls) %broadcast(Host, Node, NodeId, NodeOptions, notify_config, false, 'items', ConfigEls)
case get_option(NodeOptions, notify_config) of case get_option(NodeOptions, notify_config) of

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-05-28 13:16:05.000000000 +0200 --- mod_pubsub.erl 2010-05-28 13:26:20.000000000 +0200
+++ mod_pubsub_odbc.erl 2010-05-28 13:17:04.000000000 +0200 +++ mod_pubsub_odbc.erl 2010-05-28 13:26:29.000000000 +0200
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18. %%% XEP-0060 section 12.18.
@ -433,16 +433,16 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if if
not IsApprover -> not IsApprover ->
@@ -1818,7 +1633,7 @@ @@ -1826,7 +1641,7 @@
end, end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
- case transaction(CreateNode, transaction) of - case transaction(CreateNode, transaction) of
+ case transaction(Host, CreateNode, transaction) of + case transaction(Host, CreateNode, transaction) of
{result, {Result, broadcast}} -> {result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
%%Lang = "en", %% TODO: fix broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), case Result of
@@ -1927,7 +1742,7 @@ @@ -1930,7 +1745,7 @@
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%</ul> %%</ul>
subscribe_node(Host, Node, From, JID, Configuration) -> subscribe_node(Host, Node, From, JID, Configuration) ->
@ -451,7 +451,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -1937,7 +1752,7 @@ @@ -1940,7 +1755,7 @@
_:_ -> _:_ ->
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
@ -460,7 +460,7 @@
Features = features(Type), Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features), SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features), OptionsFeature = lists:member("subscription-options", Features),
@@ -1956,9 +1771,12 @@ @@ -1959,9 +1774,12 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -476,7 +476,7 @@
end end
end, end,
if if
@@ -2304,7 +2122,7 @@ @@ -2307,7 +2125,7 @@
%% <p>The permission are not checked in this function.</p> %% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right %% @todo We probably need to check that the user doing the query has the right
%% to read the items. %% to read the items.
@ -485,7 +485,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> get_max_items_node(Host); SMaxItems == "" -> get_max_items_node(Host);
@@ -2343,11 +2161,11 @@ @@ -2346,11 +2164,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -499,7 +499,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2360,7 +2178,7 @@ @@ -2363,7 +2181,7 @@
%% number of items sent to MaxItems: %% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = {result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -508,7 +508,7 @@
Error -> Error ->
Error Error
end end
@@ -2392,16 +2210,29 @@ @@ -2395,16 +2213,29 @@
%% @doc <p>Resend the items of a node to the user.</p> %% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature %% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) -> send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -544,7 +544,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) -> send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} -> {result, []} ->
@@ -2528,7 +2359,8 @@ @@ -2531,7 +2362,8 @@
error -> error ->
{error, 'bad-request'}; {error, 'bad-request'};
_ -> _ ->
@ -554,7 +554,7 @@
case lists:member(Owner, Owners) of case lists:member(Owner, Owners) of
true -> true ->
OwnerJID = exmpp_jid:make(Owner), OwnerJID = exmpp_jid:make(Owner),
@@ -2538,24 +2370,8 @@ @@ -2541,24 +2373,8 @@
end, end,
lists:foreach( lists:foreach(
fun({JID, Affiliation}) -> fun({JID, Affiliation}) ->
@ -581,7 +581,7 @@
end, FilteredEntities), end, FilteredEntities),
{result, []}; {result, []};
_ -> _ ->
@@ -2610,11 +2426,11 @@ @@ -2613,11 +2429,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -595,7 +595,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('subid', SubID) | nodeAttr(Node)], ?XMLATTR('subid', SubID) | nodeAttr(Node)],
@@ -2641,7 +2457,7 @@ @@ -2644,7 +2460,7 @@
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -604,7 +604,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -2671,7 +2487,7 @@ @@ -2674,7 +2490,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) -> write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")}; {error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
@ -613,7 +613,7 @@
{error, notfound} -> {error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")}; {error, extended_error('not-acceptable', "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2844,8 +2660,8 @@ @@ -2847,8 +2663,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]}, ?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza) ejabberd_router:route(service_jid(Host), JID, Stanza)
end, end,
@ -624,7 +624,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3186,7 +3002,7 @@ @@ -3194,7 +3010,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]} {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end, end,
@ -633,7 +633,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3200,9 +3016,9 @@ @@ -3208,9 +3024,9 @@
get_options_for_subs(NodeID, Subs) -> get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -645,7 +645,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3424,6 +3240,30 @@ @@ -3432,6 +3248,30 @@
Result Result
end. end.
@ -676,7 +676,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3827,7 +3667,13 @@ @@ -3835,7 +3675,13 @@
tree_action(Host, Function, Args) -> tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end, Fun = fun() -> tree_call(Host, Function, Args) end,
@ -691,7 +691,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3847,13 +3693,13 @@ @@ -3855,13 +3701,13 @@
node_action(Host, Type, Function, Args) -> node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -707,7 +707,7 @@
case tree_call(Host, get_node, [Host, Node]) of case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) -> N when is_record(N, pubsub_node) ->
case Action(N) of case Action(N) of
@@ -3866,8 +3712,15 @@ @@ -3874,8 +3720,15 @@
end end
end, Trans). end, Trans).
@ -725,7 +725,7 @@
{result, Result} -> {result, Result}; {result, Result} -> {result, Result};
{error, Error} -> {error, Error}; {error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result}; {atomic, {result, Result}} -> {result, Result};
@@ -3875,6 +3728,15 @@ @@ -3883,6 +3736,15 @@
{aborted, Reason} -> {aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'}; {error, 'internal-server-error'};
@ -741,7 +741,7 @@
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'}; {error, 'internal-server-error'};
@@ -3883,6 +3745,16 @@ @@ -3891,6 +3753,16 @@
{error, 'internal-server-error'} {error, 'internal-server-error'}
end. end.