%% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p>
%% @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
undefined ->
send_items(Host, Node, NodeId, Type, LJID, 1);
children =
itemsEls([LastItem])}],
ModifNow, ModifUSR),
- case is_tuple(Host) of
- 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
+ dispatch_items(Host, LJID, Node, Stanza)
end;
-send_items(Host, Node, NodeId, Type, {U, S, R} = LJID,
- Number) ->
+send_items(Host, Node, NodeId, Type, LJID, Number) ->
ToSend = case node_action(Host, Type, get_items,
[NodeId, LJID])
of
attrs = nodeAttr(Node),
children = itemsEls(ToSend)}])
end,
- case {is_tuple(Host), Stanza} of
- {_, undefined} ->
- ok;
- {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.
+ dispatch_items(Host, LJID, Node, Stanza).
+
+-spec(dispatch_items/4 ::
+(
+ From :: mod_pubsub:host(),
+ To :: jid(),
+ Node :: mod_pubsub:nodeId(),
+ Stanza :: xmlel() | undefined)
+ -> any()
+).
+
+dispatch_items(_From, _To, _Node, _Stanza = undefined) -> ok;
+dispatch_items(From, {U, S, R}, Node, Stanza) when is_tuple(From) ->
+ case ejabberd_sm:get_session_pid(U, S, R) of
+ C2SPid when is_pid(C2SPid) ->
+ 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}
%% Host = host()
%% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p>
%% @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
undefined ->
% special ODBC optimization, works only with node_hometree_odbc, node_flat_odbc and node_pep_odbc
itemsEls([LastItem])}],
ModifNow, ModifUSR)
end,
- case is_tuple(Host) of
- 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;
-send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, Number) ->
+ dispatch_items(Host, LJID, Node, Stanza);
+send_items(Host, Node, NodeId, Type, LJID, Number) ->
ToSend = case node_action(Host, Type, get_items,
[NodeId, LJID])
of
attrs = nodeAttr(Node),
children = itemsEls(ToSend)}])
end,
- case {is_tuple(Host), Stanza} of
- {_, undefined} ->
- ok;
- {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.
+ dispatch_items(Host, LJID, Node, Stanza).
+
+-spec(dispatch_items/4 ::
+(
+ From :: mod_pubsub:host(),
+ To :: jid(),
+ Node :: mod_pubsub:nodeId(),
+ Stanza :: xmlel() | undefined)
+ -> any()
+).
+
+dispatch_items(_From, _To, _Node, _Stanza = undefined) -> ok;
+dispatch_items(From, {U, S, R}, Node, Stanza) when is_tuple(From) ->
+ case ejabberd_sm:get_session_pid(U, S, R) of
+ C2SPid when is_pid(C2SPid) ->
+ 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}
%% Host = host()