Skip to content

Commit cda1d4c

Browse files
committed
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
1 parent 128103b commit cda1d4c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/mod_push.erl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,19 @@ notify(LServer, PushLJID, Node, XData, Pkt0, Dir, HandleResponse) ->
526526
Item = #ps_item{sub_els = [#push_notification{xdata = Summary}]},
527527
PubSub = #pubsub{publish = #ps_publish{node = Node, items = [Item]},
528528
publish_options = XData},
529-
IQ = #iq{type = set,
530-
from = From,
531-
to = jid:make(PushLJID),
532-
id = p1_rand:get_string(),
533-
sub_els = [PubSub]},
534-
ejabberd_router:route_iq(IQ, HandleResponse)
529+
IQ0 = #iq{type = set,
530+
from = From,
531+
to = jid:make(PushLJID),
532+
id = p1_rand:get_string(),
533+
sub_els = [PubSub]},
534+
case ejabberd_hooks:run_fold(push_send_notification, LServer, IQ0, [Pkt]) of
535+
drop ->
536+
?DEBUG("No push notification will be sent: some hook dropped it", []),
537+
ok;
538+
IQ ->
539+
?DEBUG("Push notification hooks built the definitive IQ to route: ~n~ts", [xmpp:pp(IQ)]),
540+
ejabberd_router:route_iq(IQ, HandleResponse)
541+
end
535542
end.
536543

537544
%%--------------------------------------------------------------------

0 commit comments

Comments
 (0)