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};
_ -> []
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} ->
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};
_ -> []
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} ->
---- 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.