24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-06 21:37:17 +02:00

Move routing of last PEP items into new function

This doesn't change the behavior, but avoids some code duplication.
This commit is contained in:
Holger Weiss 2014-11-14 00:16:13 +01:00
parent 8efae1f05b
commit 5cc30c3977
2 changed files with 50 additions and 65 deletions

View File

@ -3312,7 +3312,7 @@ get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
%% Number = last | integer() %% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p> %% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature %% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) -> send_items(Host, Node, NodeId, Type, LJID, last) ->
case get_cached_item(Host, NodeId) of case get_cached_item(Host, NodeId) of
undefined -> undefined ->
send_items(Host, Node, NodeId, Type, LJID, 1); send_items(Host, Node, NodeId, Type, LJID, 1);
@ -3325,24 +3325,9 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) ->
children = children =
itemsEls([LastItem])}], itemsEls([LastItem])}],
ModifNow, ModifUSR), ModifNow, ModifUSR),
case is_tuple(Host) of dispatch_items(Host, LJID, Node, Stanza)
false ->
ejabberd_router:route(service_jid(Host),
jlib:make_jid(LJID), Stanza);
true ->
case ejabberd_sm:get_session_pid(U, S, R) of
C2SPid when is_pid(C2SPid) ->
ejabberd_c2s:broadcast(C2SPid,
{pep_message,
<<((Node))/binary, "+notify">>},
_Sender = service_jid(Host),
Stanza);
_ -> ok
end
end
end; end;
send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, send_items(Host, Node, NodeId, Type, LJID, Number) ->
Number) ->
ToSend = case node_action(Host, Type, get_items, ToSend = case node_action(Host, Type, get_items,
[NodeId, LJID]) [NodeId, LJID])
of of
@ -3370,22 +3355,28 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID,
attrs = nodeAttr(Node), attrs = nodeAttr(Node),
children = itemsEls(ToSend)}]) children = itemsEls(ToSend)}])
end, end,
case {is_tuple(Host), Stanza} of dispatch_items(Host, LJID, Node, Stanza).
{_, undefined} ->
ok; -spec(dispatch_items/4 ::
{false, _} -> (
ejabberd_router:route(service_jid(Host), From :: mod_pubsub:host(),
jlib:make_jid(LJID), Stanza); To :: jid(),
{true, _} -> Node :: mod_pubsub:nodeId(),
case ejabberd_sm:get_session_pid(U, S, R) of Stanza :: xmlel() | undefined)
C2SPid when is_pid(C2SPid) -> -> any()
ejabberd_c2s:broadcast(C2SPid, ).
{pep_message,
<<((Node))/binary, "+notify">>}, dispatch_items(_From, _To, _Node, _Stanza = undefined) -> ok;
_Sender = service_jid(Host), Stanza); dispatch_items(From, {U, S, R}, Node, Stanza) when is_tuple(From) ->
_ -> ok case ejabberd_sm:get_session_pid(U, S, R) of
end C2SPid when is_pid(C2SPid) ->
end. ejabberd_c2s:broadcast(C2SPid,
{pep_message, <<((Node))/binary, "+notify">>},
service_jid(From), Stanza);
_ -> ok
end;
dispatch_items(From, To, _Node, Stanza) ->
ejabberd_router:route(service_jid(From), jlib:make_jid(To), Stanza).
%% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response} %% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response}
%% Host = host() %% Host = host()

View File

@ -2986,7 +2986,7 @@ get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
%% Number = last | integer() %% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p> %% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature %% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) -> send_items(Host, Node, NodeId, Type, LJID, last) ->
Stanza = case get_cached_item(Host, NodeId) of Stanza = case get_cached_item(Host, NodeId) of
undefined -> undefined ->
% special ODBC optimization, works only with node_hometree_odbc, node_flat_odbc and node_pep_odbc % special ODBC optimization, works only with node_hometree_odbc, node_flat_odbc and node_pep_odbc
@ -3011,20 +3011,8 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) ->
itemsEls([LastItem])}], itemsEls([LastItem])}],
ModifNow, ModifUSR) ModifNow, ModifUSR)
end, end,
case is_tuple(Host) of dispatch_items(Host, LJID, Node, Stanza);
false -> send_items(Host, Node, NodeId, Type, LJID, Number) ->
ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza);
true ->
case ejabberd_sm:get_session_pid(U, S, R) of
C2SPid when is_pid(C2SPid) ->
ejabberd_c2s:broadcast(C2SPid,
{pep_message,
<<((Node))/binary, "+notify">>},
_Sender = service_jid(Host), Stanza);
_ -> ok
end
end;
send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, ToSend = case node_action(Host, Type, get_items,
[NodeId, LJID]) [NodeId, LJID])
of of
@ -3052,22 +3040,28 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, Number) ->
attrs = nodeAttr(Node), attrs = nodeAttr(Node),
children = itemsEls(ToSend)}]) children = itemsEls(ToSend)}])
end, end,
case {is_tuple(Host), Stanza} of dispatch_items(Host, LJID, Node, Stanza).
{_, undefined} ->
ok; -spec(dispatch_items/4 ::
{false, _} -> (
ejabberd_router:route(service_jid(Host), From :: mod_pubsub:host(),
jlib:make_jid(LJID), Stanza); To :: jid(),
{true, _} -> Node :: mod_pubsub:nodeId(),
case ejabberd_sm:get_session_pid(U, S, R) of Stanza :: xmlel() | undefined)
C2SPid when is_pid(C2SPid) -> -> any()
ejabberd_c2s:broadcast(C2SPid, ).
{pep_message,
<<((Node))/binary, "+notify">>}, dispatch_items(_From, _To, _Node, _Stanza = undefined) -> ok;
_Sender = service_jid(Host), Stanza); dispatch_items(From, {U, S, R}, Node, Stanza) when is_tuple(From) ->
_ -> ok case ejabberd_sm:get_session_pid(U, S, R) of
end C2SPid when is_pid(C2SPid) ->
end. ejabberd_c2s:broadcast(C2SPid,
{pep_message, <<((Node))/binary, "+notify">>},
service_jid(From), Stanza);
_ -> ok
end;
dispatch_items(From, To, _Node, Stanza) ->
ejabberd_router:route(service_jid(From), jlib:make_jid(To), Stanza).
%% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response} %% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response}
%% Host = host() %% Host = host()