From cda1d4ce7fb46588341b00ad0f32ca4416dbc098 Mon Sep 17 00:00:00 2001 From: Marcos de Vera Piquero Date: Fri, 9 May 2025 12:43:25 +0200 Subject: [PATCH] feat: fire new `push_send_notification` hook Do not route XEP-357 IQ notification directly but run it through registered hooks that will ultimately decide whether or not send it and, if needed, customize the notification contents. Hooks can return: - a modified IQ packet, as per their business logic - the atom `drop`, to effectively cancel the push notification --- src/mod_push.erl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mod_push.erl b/src/mod_push.erl index fb5ba1be4..5165b069d 100644 --- a/src/mod_push.erl +++ b/src/mod_push.erl @@ -526,12 +526,19 @@ notify(LServer, PushLJID, Node, XData, Pkt0, Dir, HandleResponse) -> Item = #ps_item{sub_els = [#push_notification{xdata = Summary}]}, PubSub = #pubsub{publish = #ps_publish{node = Node, items = [Item]}, publish_options = XData}, - IQ = #iq{type = set, - from = From, - to = jid:make(PushLJID), - id = p1_rand:get_string(), - sub_els = [PubSub]}, - ejabberd_router:route_iq(IQ, HandleResponse) + IQ0 = #iq{type = set, + from = From, + to = jid:make(PushLJID), + id = p1_rand:get_string(), + sub_els = [PubSub]}, + case ejabberd_hooks:run_fold(push_send_notification, LServer, IQ0, [Pkt]) of + drop -> + ?DEBUG("No push notification will be sent: some hook dropped it", []), + ok; + IQ -> + ?DEBUG("Push notification hooks built the definitive IQ to route: ~n~ts", [xmpp:pp(IQ)]), + ejabberd_router:route_iq(IQ, HandleResponse) + end end. %%--------------------------------------------------------------------