From af7fe0c21ec41e307b381bc96b7d3ff87b08eaa3 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Fri, 28 May 2010 13:34:05 +0200 Subject: [PATCH] send created node notifications (EJAB-1225) --- src/mod_pubsub/mod_pubsub.erl | 36 +++++++++++++------- src/mod_pubsub/mod_pubsub_odbc.erl | 36 +++++++++++++------- src/mod_pubsub/pubsub_odbc.patch | 54 +++++++++++++++--------------- 3 files changed, 73 insertions(+), 53 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index fa1e58f76..0e0491863 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -1734,11 +1734,19 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> end, case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of {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 {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}} -> - 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 end; @@ -1750,20 +1758,15 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> [{xmlelement, "create", nodeAttr(Node), []}]}], case transaction(CreateNode, transaction) of - {result, {Result, broadcast}} -> - %%Lang = "en", %% TODO: fix - %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - %%broadcast_publish_item(Host, Node, uniqid(), Owner, - %% [{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "result"}], - %% [?XFIELD("hidden", "", "FORM_TYPE", ?NS_PUBSUB_NMI), - %% ?XFIELD("jid-single", "Node Creator", "creator", jlib:jid_to_string(OwnerKey))]}]), + {result, {NodeId, SubsByDepth, {Result, broadcast}}} -> + broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth), case Result of default -> {result, Reply}; _ -> {result, Result} end; - {result, default} -> + {result, {_NodeId, _SubsByDepth, default}} -> {result, Reply}; - {result, Result} -> + {result, {_NodeId, _SubsByDepth, Result}} -> {result, Result}; Error -> %% in case we change transaction to sync_dirty... @@ -3034,7 +3037,7 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> case get_option(NodeOptions, notify_delete) of true -> case SubsByDepth of - [] -> + [] -> {result, false}; _ -> Stanza = event_stanza( @@ -3048,6 +3051,13 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> {result, false} end. +broadcast_created_node(_, _, _, _, _, []) -> + {result, false}; +broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> + Stanza = event_stanza([{xmlelement, "create", nodeAttr(Node), []}]), + broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, true), + {result, true}. + broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> case get_option(NodeOptions, notify_config) of true -> @@ -3065,7 +3075,7 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, false), {result, true}; - _ -> + _ -> {result, false} end; _ -> diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index 2ed6d2268..058eb71a5 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -1544,11 +1544,19 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> end, case node_call(Type, create_node_permission, [Host, ServerHost, Node, Parent, Owner, Access]) of {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 {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}} -> - 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 end; @@ -1560,20 +1568,15 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> [{xmlelement, "create", nodeAttr(Node), []}]}], case transaction(Host, CreateNode, transaction) of - {result, {Result, broadcast}} -> - %%Lang = "en", %% TODO: fix - %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - %%broadcast_publish_item(Host, Node, uniqid(), Owner, - %% [{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "result"}], - %% [?XFIELD("hidden", "", "FORM_TYPE", ?NS_PUBSUB_NMI), - %% ?XFIELD("jid-single", "Node Creator", "creator", jlib:jid_to_string(OwnerKey))]}]), + {result, {NodeId, SubsByDepth, {Result, broadcast}}} -> + broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth), case Result of default -> {result, Reply}; _ -> {result, Result} end; - {result, default} -> + {result, {_NodeId, _SubsByDepth, default}} -> {result, Reply}; - {result, Result} -> + {result, {_NodeId, _SubsByDepth, Result}} -> {result, Result}; Error -> %% in case we change transaction to sync_dirty... @@ -2844,7 +2847,7 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> case get_option(NodeOptions, notify_delete) of true -> case SubsByDepth of - [] -> + [] -> {result, false}; _ -> Stanza = event_stanza( @@ -2858,6 +2861,13 @@ broadcast_removed_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> {result, false} end. +broadcast_created_node(_, _, _, _, _, []) -> + {result, false}; +broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth) -> + Stanza = event_stanza([{xmlelement, "create", nodeAttr(Node), []}]), + broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, true), + {result, true}. + broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> case get_option(NodeOptions, notify_config) of true -> @@ -2875,7 +2885,7 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) -> broadcast_stanza(Host, Node, NodeId, Type, NodeOptions, SubsByDepth, nodes, Stanza, false), {result, true}; - _ -> + _ -> {result, false} end; _ -> diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index 6ede7dfed..1a5b9dd92 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2010-05-28 12:30:32.000000000 +0200 -+++ mod_pubsub_odbc.erl 2010-05-28 12:32:45.000000000 +0200 +--- mod_pubsub.erl 2010-05-28 13:32:18.000000000 +0200 ++++ mod_pubsub_odbc.erl 2010-05-28 13:33:37.000000000 +0200 @@ -42,7 +42,7 @@ %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% XEP-0060 section 12.18. @@ -450,16 +450,16 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), if not IsApprover -> -@@ -1749,7 +1559,7 @@ +@@ -1757,7 +1567,7 @@ Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "create", nodeAttr(Node), []}]}], - case transaction(CreateNode, transaction) of + case transaction(Host, CreateNode, transaction) of - {result, {Result, broadcast}} -> - %%Lang = "en", %% TODO: fix - %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), -@@ -1857,7 +1667,7 @@ + {result, {NodeId, SubsByDepth, {Result, broadcast}}} -> + broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth), + case Result of +@@ -1860,7 +1670,7 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -468,7 +468,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -1865,7 +1675,7 @@ +@@ -1868,7 +1678,7 @@ error -> {"", "", ""}; J -> jlib:jid_tolower(J) end, @@ -477,7 +477,7 @@ Features = features(Type), SubscribeFeature = lists:member("subscribe", Features), OptionsFeature = lists:member("subscription-options", Features), -@@ -1884,9 +1694,13 @@ +@@ -1887,9 +1697,13 @@ {"", "", ""} -> {false, false}; _ -> @@ -494,7 +494,7 @@ end end, if -@@ -2217,7 +2031,7 @@ +@@ -2220,7 +2034,7 @@ %%

    The permission are not checked in this function.

    %% @todo We probably need to check that the user doing the query has the right %% to read the items. @@ -503,7 +503,7 @@ MaxItems = if SMaxItems == "" -> get_max_items_node(Host); -@@ -2256,11 +2070,11 @@ +@@ -2259,11 +2073,11 @@ node_call(Type, get_items, [NodeId, From, AccessModel, PresenceSubscription, RosterGroup, @@ -517,7 +517,7 @@ SendItems = case ItemIDs of [] -> Items; -@@ -2273,7 +2087,8 @@ +@@ -2276,7 +2090,8 @@ %% number of items sent to MaxItems: {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "items", nodeAttr(Node), @@ -527,7 +527,7 @@ Error -> Error end -@@ -2305,16 +2120,27 @@ +@@ -2308,16 +2123,27 @@ %% @doc

    Resend the items of a node to the user.

    %% @todo use cache-last-item feature send_items(Host, Node, NodeId, Type, LJID, last) -> @@ -561,7 +561,7 @@ send_items(Host, Node, NodeId, Type, LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of {result, []} -> -@@ -2440,7 +2266,8 @@ +@@ -2443,7 +2269,8 @@ error -> {error, ?ERR_BAD_REQUEST}; _ -> @@ -571,7 +571,7 @@ case lists:member(Owner, Owners) of true -> OwnerJID = jlib:make_jid(Owner), -@@ -2450,24 +2277,7 @@ +@@ -2453,24 +2280,7 @@ end, lists:foreach( fun({JID, Affiliation}) -> @@ -597,7 +597,7 @@ end, FilteredEntities), {result, []}; _ -> -@@ -2520,11 +2330,11 @@ +@@ -2523,11 +2333,11 @@ end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> @@ -611,7 +611,7 @@ OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)}, {"subid", SubID}|nodeAttr(Node)], [XdataEl]}, -@@ -2550,7 +2360,7 @@ +@@ -2553,7 +2363,7 @@ end. set_options_helper(Configuration, JID, NodeID, SubID, Type) -> @@ -620,7 +620,7 @@ {result, GoodSubOpts} -> GoodSubOpts; _ -> invalid end, -@@ -2579,7 +2389,7 @@ +@@ -2582,7 +2392,7 @@ write_sub(_Subscriber, _NodeID, _SubID, invalid) -> {error, extended_error(?ERR_BAD_REQUEST, "invalid-options")}; write_sub(Subscriber, NodeID, SubID, Options) -> @@ -629,7 +629,7 @@ {error, notfound} -> {error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {result, _} -> -@@ -2747,8 +2557,8 @@ +@@ -2750,8 +2560,8 @@ {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]}, ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza) end, @@ -640,7 +640,7 @@ true -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> -@@ -3078,7 +2888,7 @@ +@@ -3088,7 +2898,7 @@ {Depth, [{N, get_node_subs(N)} || N <- Nodes]} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, @@ -649,7 +649,7 @@ {result, CollSubs} -> CollSubs; _ -> [] end. -@@ -3092,9 +2902,9 @@ +@@ -3102,9 +2912,9 @@ get_options_for_subs(NodeID, Subs) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) -> @@ -661,7 +661,7 @@ _ -> Acc end; (_, Acc) -> -@@ -3298,6 +3108,30 @@ +@@ -3308,6 +3118,30 @@ Result end. @@ -692,7 +692,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3694,7 +3528,13 @@ +@@ -3704,7 +3538,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -707,7 +707,7 @@ %% @doc

    node plugin call.

    node_call(Type, Function, Args) -> -@@ -3714,13 +3554,13 @@ +@@ -3724,13 +3564,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -723,7 +723,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3733,8 +3573,14 @@ +@@ -3743,8 +3583,14 @@ end end, Trans). @@ -740,7 +740,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3742,6 +3588,15 @@ +@@ -3752,6 +3598,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; @@ -756,7 +756,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; -@@ -3750,6 +3605,17 @@ +@@ -3760,6 +3615,17 @@ {error, ?ERR_INTERNAL_SERVER_ERROR} end.