From faa6ad26a0d1a0968b008642f64a3a5766f9a40e Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Mon, 5 May 2014 13:51:02 +0200 Subject: [PATCH] avoid sending empty events --- src/mod_pubsub.erl | 10 +++++++--- src/mod_pubsub_odbc.erl | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index 8cbd994e0..1d8bd143c 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -3356,6 +3356,8 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, _ -> [] end, Stanza = case ToSend of + [] -> + undefined; [LastItem] -> {ModifNow, ModifUSR} = LastItem#pubsub_item.modification, @@ -3369,11 +3371,13 @@ send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, attrs = nodeAttr(Node), children = itemsEls(ToSend)}]) end, - case is_tuple(Host) of - false -> + case {is_tuple(Host), Stanza} of + {_, undefined} -> + ok; + {false, _} -> ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza); - true -> + {true, _} -> case ejabberd_sm:get_session_pid(U, S, R) of C2SPid when is_pid(C2SPid) -> ejabberd_c2s:broadcast(C2SPid, diff --git a/src/mod_pubsub_odbc.erl b/src/mod_pubsub_odbc.erl index 8236447d0..498c81bd3 100644 --- a/src/mod_pubsub_odbc.erl +++ b/src/mod_pubsub_odbc.erl @@ -3013,7 +3013,7 @@ send_items(Host, Node, NodeId, Type, LJID, last) -> ModifNow, ModifUSR) end, ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza); -send_items(Host, Node, NodeId, Type, LJID, Number) -> +send_items(Host, Node, NodeId, Type, {U, S, R} = LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of @@ -3026,6 +3026,8 @@ send_items(Host, Node, NodeId, Type, LJID, Number) -> _ -> [] end, Stanza = case ToSend of + [] -> + undefined; [LastItem] -> {ModifNow, ModifUSR} = LastItem#pubsub_item.modification, @@ -3039,7 +3041,22 @@ send_items(Host, Node, NodeId, Type, LJID, Number) -> attrs = nodeAttr(Node), children = itemsEls(ToSend)}]) end, - ejabberd_router:route(service_jid(Host), jlib:make_jid(LJID), Stanza). + 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. %% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response} %% Host = host()