1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 09:49:18 +02:00

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
This commit is contained in:
Marcos de Vera Piquero 2025-05-09 12:43:25 +02:00
parent 128103b7b2
commit cda1d4ce7f

View file

@ -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,
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.
%%--------------------------------------------------------------------