]> granicus.if.org Git - ejabberd/commitdiff
fix previous commit issues
authorChristophe Romain <christophe.romain@process-one.net>
Wed, 9 Feb 2011 13:27:40 +0000 (14:27 +0100)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 9 Feb 2011 13:27:40 +0000 (14:27 +0100)
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/pubsub_odbc.patch

index c761c1f44f47ca68334aeef4526c2d70cd18fa04..82132f652b7b8891d720b918dbd0ee8e86bd789b 100644 (file)
@@ -2468,7 +2468,7 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
                                   broadcast -> Payload;
                                   PluginPayload -> PluginPayload
                               end,
-           broadcast_publish_item(Host, Node, Nidx, Type, Options, ItemId, jlib:short_prepd_jid(Publisher), BrPayloadi, Removed),
+           broadcast_publish_item(Host, Node, Nidx, Type, Options, ItemId, jlib:short_prepd_jid(Publisher), BrPayload, Removed),
            set_cached_item(Host, Nidx, ItemId, Publisher, Payload),
            case Result of
                default -> {result, Reply};
@@ -3547,6 +3547,59 @@ node_subscriptions_full(Host, Node, NotifyType) ->
        _ -> []
      end.
 
+ subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
+     NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
+            NodeName = case Node#pubsub_node.id of
+                {_, N} -> N;
+                Other -> Other
+            end,
+            NodeOptions = Node#pubsub_node.options,
+            lists:foldl(fun({LJID, SubId, SubOptions}, {JIDs, Recipients}) ->
+                        case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of
+                            true  ->
+                                %% If is to deliver :
+                                case state_can_deliver(LJID, SubOptions) of
+                                    []            -> {JIDs, Recipients};
+                                    JIDsToDeliver ->
+                                        lists:foldl(
+                                            fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) ->
+                                                    case lists:member(JIDToDeliver, JIDs) of
+                                                        %% check if the JIDs co-accumulator contains the Subscription JID,
+                                                        false ->
+                                                            %%  - if not,
+                                                            %%  - add the JID to JIDs list co-accumulator ;
+                                                            %%  - create a tuple of the JID, NodeId, and SubId (as list),
+                                                            %%    and add the tuple to the Recipients list co-accumulator
+                                                            {[JIDToDeliver | JIDsAcc], [{JIDToDeliver, NodeName, [SubId]} | RecipientsAcc]};
+                                                        true ->
+                                                            %% - if the JIDs co-accumulator contains the JID
+                                                            %%   get the tuple containing the JID from the Recipient list co-accumulator
+                                                            {_, {JIDToDeliver, NodeName1, SubIds}} = lists:keysearch(JIDToDeliver, 1, RecipientsAcc),
+                                                            %%   delete the tuple from the Recipients list
+                                                            % v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients),
+                                                            % v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, NodeId1, [SubId | SubIds]}),
+                                                            %%   add the SubId to the SubIds list in the tuple,
+                                                            %%   and add the tuple back to the Recipients list co-accumulator
+                                                            % v1.1 : {JIDs, lists:append(Recipients1, [{LJID, NodeId1, lists:append(SubIds, [SubId])}])}
+                                                            % v1.2 : {JIDs, [{LJID, NodeId1, [SubId | SubIds]} | Recipients1]}
+                                                            % v2: {JIDs, Recipients1}
+                                                            {JIDsAcc, lists:keyreplace(JIDToDeliver, 1, RecipientsAcc, {JIDToDeliver, NodeName1, [SubId | SubIds]})}
+                                                    end
+                                            end, {JIDs, Recipients}, JIDsToDeliver)
+                                end;
+                            false ->
+                                {JIDs, Recipients}
+                        end
+                end, Acc, Subs)
+     end,
+     DepthsToDeliver = fun({Depth, SubsByNode}, Acc1) ->
+            lists:foldl(fun({Node, Subs}, Acc2) ->
+                        NodesToDeliver(Depth, Node, Subs, Acc2)
+                end, Acc1, SubsByNode)
+     end,
+     {_, JIDSubs} = lists:foldl(DepthsToDeliver, {[], []}, SubsByDepth),
+     JIDSubs.
+
 sub_with_options(#pubsub_node{type = Type, id = NodeId}) ->
     case node_call(Type, get_node_subscriptions, [NodeId]) of
        {result, Subs} ->
index 6d8e929c72a73a1b19e7867b22816d5c0577090c..e1e63ecca7172b30e4470cb5512eaba3caefc632 100644 (file)
@@ -2263,7 +2263,7 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
                                   broadcast -> Payload;
                                   PluginPayload -> PluginPayload
                               end,
-           broadcast_publish_item(Host, Node, Nidx, Type, Options, ItemId, jlib:short_prepd_jid(Publisher), BrPayloadi, Removed),
+           broadcast_publish_item(Host, Node, Nidx, Type, Options, ItemId, jlib:short_prepd_jid(Publisher), BrPayload, Removed),
            set_cached_item(Host, Nidx, ItemId, Publisher, Payload),
            case Result of
                default -> {result, Reply};
@@ -3352,6 +3352,59 @@ node_subscriptions_full(Host, Node, NotifyType) ->
        _ -> []
      end.
 
+ subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
+     NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
+            NodeName = case Node#pubsub_node.id of
+                {_, N} -> N;
+                Other -> Other
+            end,
+            NodeOptions = Node#pubsub_node.options,
+            lists:foldl(fun({LJID, SubId, SubOptions}, {JIDs, Recipients}) ->
+                        case is_to_deliver(LJID, NotifyType, Depth, NodeOptions, SubOptions) of
+                            true  ->
+                                %% If is to deliver :
+                                case state_can_deliver(LJID, SubOptions) of
+                                    []            -> {JIDs, Recipients};
+                                    JIDsToDeliver ->
+                                        lists:foldl(
+                                            fun(JIDToDeliver, {JIDsAcc, RecipientsAcc}) ->
+                                                    case lists:member(JIDToDeliver, JIDs) of
+                                                        %% check if the JIDs co-accumulator contains the Subscription JID,
+                                                        false ->
+                                                            %%  - if not,
+                                                            %%  - add the JID to JIDs list co-accumulator ;
+                                                            %%  - create a tuple of the JID, NodeId, and SubId (as list),
+                                                            %%    and add the tuple to the Recipients list co-accumulator
+                                                            {[JIDToDeliver | JIDsAcc], [{JIDToDeliver, NodeName, [SubId]} | RecipientsAcc]};
+                                                        true ->
+                                                            %% - if the JIDs co-accumulator contains the JID
+                                                            %%   get the tuple containing the JID from the Recipient list co-accumulator
+                                                            {_, {JIDToDeliver, NodeName1, SubIds}} = lists:keysearch(JIDToDeliver, 1, RecipientsAcc),
+                                                            %%   delete the tuple from the Recipients list
+                                                            % v1 : Recipients1 = lists:keydelete(LJID, 1, Recipients),
+                                                            % v2 : Recipients1 = lists:keyreplace(LJID, 1, Recipients, {LJID, NodeId1, [SubId | SubIds]}),
+                                                            %%   add the SubId to the SubIds list in the tuple,
+                                                            %%   and add the tuple back to the Recipients list co-accumulator
+                                                            % v1.1 : {JIDs, lists:append(Recipients1, [{LJID, NodeId1, lists:append(SubIds, [SubId])}])}
+                                                            % v1.2 : {JIDs, [{LJID, NodeId1, [SubId | SubIds]} | Recipients1]}
+                                                            % v2: {JIDs, Recipients1}
+                                                            {JIDsAcc, lists:keyreplace(JIDToDeliver, 1, RecipientsAcc, {JIDToDeliver, NodeName1, [SubId | SubIds]})}
+                                                    end
+                                            end, {JIDs, Recipients}, JIDsToDeliver)
+                                end;
+                            false ->
+                                {JIDs, Recipients}
+                        end
+                end, Acc, Subs)
+     end,
+     DepthsToDeliver = fun({Depth, SubsByNode}, Acc1) ->
+            lists:foldl(fun({Node, Subs}, Acc2) ->
+                        NodesToDeliver(Depth, Node, Subs, Acc2)
+                end, Acc1, SubsByNode)
+     end,
+     {_, JIDSubs} = lists:foldl(DepthsToDeliver, {[], []}, SubsByDepth),
+     JIDSubs.
+
 sub_with_options(#pubsub_node{type = Type, id = NodeId}) ->
     case node_call(Type, get_node_subscriptions, [NodeId]) of
        {result, Subs} ->
index a8910c86a9919d9572251ceea44ed2b3d794c019..55cacb192f1e1d5565ceccf64bd68d059dd27f63 100644 (file)
@@ -1,5 +1,5 @@
---- mod_pubsub.erl     2011-02-08 18:52:12.000000000 +0100
-+++ mod_pubsub_odbc.erl        2011-02-08 19:07:44.000000000 +0100
+--- mod_pubsub.erl     2011-02-09 14:26:03.000000000 +0100
++++ mod_pubsub_odbc.erl        2011-02-09 14:26:41.000000000 +0100
 @@ -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, CollSubs} -> subscribed_nodes_by_jid(NotifyType, CollSubs);
        _ -> []
       end.
-@@ -3558,8 +3363,8 @@
+@@ -3611,8 +3416,8 @@
            []
      end.
  sub_with_options(JID, NodeId, SubId) ->
        _ -> {JID, SubId, []}
      end.
  
-@@ -3671,6 +3476,30 @@
+@@ -3724,6 +3529,30 @@
            Result
      end.
  
  %% @spec (Host, Options) -> MaxItems
  %%     Host = host()
  %%     Options = [Option]
-@@ -4194,9 +4023,14 @@
+@@ -4247,9 +4076,14 @@
  
  tree_action(Host, Function, Args) ->
      ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
  
  %% @doc <p>node plugin call.</p>
  -spec(node_call/3 ::
-@@ -4234,7 +4068,7 @@
+@@ -4287,7 +4121,7 @@
  
  node_action(Host, Type, Function, Args) ->
      ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
                        node_call(Type, Function, Args)
                end, sync_dirty).
  
-@@ -4249,7 +4083,7 @@
+@@ -4302,7 +4136,7 @@
            ).
  
  transaction(Host, NodeId, Action, Trans) ->
                        case tree_call(Host, get_node, [Host, NodeId]) of
                            #pubsub_node{} = Node ->
                                case Action(Node) of
-@@ -4263,7 +4097,7 @@
+@@ -4316,7 +4150,7 @@
                end, Trans).
  
  
        (
                    Host   :: string() | host(),
                    Action :: fun(),
-@@ -4271,21 +4105,28 @@
+@@ -4324,21 +4158,28 @@
        -> {'result', Nodes :: [] | [Node::pubsubNode()]}
            ).
  
        {result, Result} -> {result, Result};
        {error, Error} -> {error, Error};
        {atomic, {result, Result}} -> {result, Result};
-@@ -4293,6 +4134,15 @@
+@@ -4346,6 +4187,15 @@
        {aborted, Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
            {error, 'internal-server-error'};
        {'EXIT', Reason} ->
            ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
            {error, 'internal-server-error'};
-@@ -4301,6 +4151,16 @@
+@@ -4354,6 +4204,16 @@
            {error, 'internal-server-error'}
      end.