]> granicus.if.org Git - ejabberd/commitdiff
resolve EJAB-1025, send notification when owner changed entity subscription
authorChristophe Romain <christophe.romain@process-one.net>
Tue, 25 Aug 2009 16:35:43 +0000 (16:35 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Tue, 25 Aug 2009 16:35:43 +0000 (16:35 +0000)
SVN Revision: 2532

src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/pubsub_odbc.patch

index 5bee62705818742b6745c05efa4e24c584dbbc05..3469173fe745e42f52480b6dac75d886500e0082 100644 (file)
@@ -2672,6 +2672,15 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
        error ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
+           Notify = fun(JID, Sub, _SubId) ->
+               Stanza = {xmlelement, "message", [],
+                           [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
+                               [{xmlelement, "subscription",
+                                   [{"jid", jlib:jid_to_string(JID)}, 
+                                   %{"subid", SubId},
+                                    {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
+               ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
+           end,
            Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
                            case lists:member(Owner, Owners) of
                                true ->
@@ -2679,7 +2688,7 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
 
                                                    case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of
                                                        {error, Err} -> [{error, Err} | Acc];
-                                                       _ -> Acc
+                                                       _ -> Notify(JID, Subscription, SubId), Acc
                                                    end
                                                end, [], Entities),
                                    case Result of
index 3bad02fb7ddec0a97c7a2467fac914624ba07ee5..23c7daae0ef127b8a4ed65b46fc2013e2b09fd16 100644 (file)
@@ -2673,6 +2673,15 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
        error ->
            {error, ?ERR_BAD_REQUEST};
        _ ->
+           Notify = fun(JID, Sub, _SubId) ->
+               Stanza = {xmlelement, "message", [],
+                           [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
+                               [{xmlelement, "subscription",
+                                   [{"jid", jlib:jid_to_string(JID)}, 
+                                   %{"subid", SubId},
+                                    {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
+               ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
+           end,
            Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
                            case lists:member(Owner, node_owners_call(Type, NodeId)) of
                                true ->
@@ -2680,7 +2689,7 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
 
                                                    case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of
                                                        {error, Err} -> [{error, Err} | Acc];
-                                                       _ -> Acc
+                                                       _ -> Notify(JID, Subscription, SubId), Acc
                                                    end
                                                end, [], Entities),
                                    case Result of
index 88f976b8f36da7dfff395d870acb13e2a14014f1..ae4f13ae7b1911c1964ecc3e455e5acfb38232e5 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2009-08-25 16:10:58.000000000 +0200
-+++ mod_pubsub_odbc.erl        2009-08-25 16:12:30.000000000 +0200
+--- mod_pubsub.erl     2009-08-25 18:29:16.000000000 +0200
++++ mod_pubsub_odbc.erl        2009-08-25 18:34:37.000000000 +0200
 @@ -45,7 +45,7 @@
  %%% TODO
  %%% plugin: generate Reply (do not use broadcast atom anymore)
                                    end, Entities),
                                {result, []};
                            _ ->
-@@ -2672,8 +2673,8 @@
-       error ->
-           {error, ?ERR_BAD_REQUEST};
-       _ ->
+@@ -2681,8 +2682,8 @@
+                                    {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
+               ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
+           end,
 -          Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
 -                          case lists:member(Owner, Owners) of
 +          Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
                                true ->
                                    Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
  
-@@ -3170,6 +3171,30 @@
+@@ -3179,6 +3180,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -3543,7 +3568,13 @@
+@@ -3552,7 +3577,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) ->
-@@ -3563,13 +3594,13 @@
+@@ -3572,13 +3603,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
-@@ -3582,8 +3613,14 @@
+@@ -3591,8 +3622,14 @@
                        end
                end, Trans).
  
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -3591,6 +3628,15 @@
+@@ -3600,6 +3637,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};
-@@ -3599,6 +3645,17 @@
+@@ -3608,6 +3654,17 @@
            {error, ?ERR_INTERNAL_SERVER_ERROR}
      end.