aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2014-11-14 00:16:13 +0100
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-11-14 00:16:13 +0100
commit5cc30c39778c73b274bfa67bea0c355b5fc0ac74 (patch)
treeb738a4e05118acaa4f103db30bf87362c0aa7919 /src
parentODBC: Sync last item notifications with mod_pubsub (diff)
Move routing of last PEP items into new function
This doesn't change the behavior, but avoids some code duplication.
Diffstat (limited to 'src')
-rw-r--r--src/mod_pubsub.erl59
-rw-r--r--src/mod_pubsub_odbc.erl56
2 files changed, 50 insertions, 65 deletions
diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl
index 91b5afead..0cd84fd2f 100644
--- a/src/mod_pubsub.erl
+++ b/src/mod_pubsub.erl
@@ -3312,7 +3312,7 @@ get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
%% 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);
@@ -3325,24 +3325,9 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) ->
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
@@ -3370,22 +3355,28 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID,
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()
diff --git a/src/mod_pubsub_odbc.erl b/src/mod_pubsub_odbc.erl
index 87d553523..821add288 100644
--- a/src/mod_pubsub_odbc.erl
+++ b/src/mod_pubsub_odbc.erl
@@ -2986,7 +2986,7 @@ get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
%% 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
@@ -3011,20 +3011,8 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, last) ->
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
@@ -3052,22 +3040,28 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, Number) ->
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()