]> granicus.if.org Git - ejabberd/commitdiff
send created node notifications (EJAB-1225)
authorChristophe Romain <chris.romain@gmail.com>
Fri, 28 May 2010 11:34:05 +0000 (13:34 +0200)
committerChristophe Romain <chris.romain@gmail.com>
Fri, 28 May 2010 11:34:05 +0000 (13:34 +0200)
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/pubsub_odbc.patch

index fa1e58f760a4430eac0da71fd30c1b1126b8374f..0e04918631b59c7863572d71e9cd81376499a9a8 100644 (file)
@@ -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;
        _ ->
index 2ed6d226823ee233d214c9b54791ec1430faa8db..058eb71a5e869022a35e4d60e71ab1b476ee33a0 100644 (file)
@@ -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;
        _ ->
index 6ede7dfed65aefb22abd3906550403ea0b2052f5..1a5b9dd92874b90541f4c2e96288c10c9044c5d4 100644 (file)
@@ -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.
                             {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 @@
  %%<li>The node does not exist.</li>
  %%</ul>
  subscribe_node(Host, Node, From, JID, Configuration) ->
        {result, GoodSubOpts} -> GoodSubOpts;
        _ -> invalid
      end,
-@@ -1865,7 +1675,7 @@
+@@ -1868,7 +1678,7 @@
                     error -> {"", "", ""};
                     J -> jlib:jid_tolower(J)
                 end,
                    Features = features(Type),
                    SubscribeFeature = lists:member("subscribe", Features),
                    OptionsFeature = lists:member("subscription-options", Features),
-@@ -1884,9 +1694,13 @@
+@@ -1887,9 +1697,13 @@
                                    {"", "", ""} ->
                                        {false, false};
                                    _ ->
                                end
                        end,
                    if
-@@ -2217,7 +2031,7 @@
+@@ -2220,7 +2034,7 @@
  %% <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
  %% to read the items.
      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,
                    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),
                Error ->
                    Error
            end
-@@ -2305,16 +2120,27 @@
+@@ -2308,16 +2123,27 @@
  %% @doc <p>Resend the items of a node to the user.</p>
  %% @todo use cache-last-item feature
  send_items(Host, Node, NodeId, Type, LJID, last) ->
  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};
        _ ->
                        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}) ->
                                    end, FilteredEntities),
                                {result, []};
                            _ ->
-@@ -2520,11 +2330,11 @@
+@@ -2523,11 +2333,11 @@
      end.
  
  read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
            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) ->
        {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) ->
        {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,
                                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,
        {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) ->
                            _ -> Acc
                        end;
                    (_, Acc) ->
-@@ -3298,6 +3108,30 @@
+@@ -3308,6 +3118,30 @@
            Result
      end.
  
  %% @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,
  
  %% @doc <p>node plugin call.</p>
  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]),
                        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).
  
        {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};
        {'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.