# HG changeset patch # User Matthew Wild # Date 1610464906 0 # Node ID 9b95241c6ae5af1da662bee175d794e255b797a7 # Parent 45dcf5d4cd6c5a9cc68940f14b27192a274f2ea3 mod_cloud_notify: Fire register and push events for integration with other modules diff -r 45dcf5d4cd6c -r 9b95241c6ae5 mod_cloud_notify/mod_cloud_notify.lua --- a/mod_cloud_notify/mod_cloud_notify.lua Mon Jan 11 22:48:17 2021 +0100 +++ b/mod_cloud_notify/mod_cloud_notify.lua Tue Jan 12 15:21:46 2021 +0000 @@ -189,6 +189,12 @@ options = publish_options and st.preserialize(publish_options); timestamp = os_time(); }; + local allow_registration = module:fire_event("cloud_notify/registration", { + origin = origin, stanza = stanza, push_info = push_service; + }); + if allow_registration == false then + return true; -- Assume error reply already sent + end push_store:set_identifier(origin.username, push_identifier, push_service); local ok = push_store:flush_to_disk(origin.username); if not ok then @@ -347,16 +353,28 @@ node, module.host, push_info.jid, tostring(push_info.node) ); -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish)); - -- handle push errors for this node - if push_errors[push_identifier] == nil then - push_errors[push_identifier] = 0; + local push_event = { + notification_stanza = push_publish; + original_stanza = stanza; + node = node; + push_info = push_info; + push_summary = form_data; + }; + + if module:fire_event("cloud_notify/push", push_event) then + module:log("debug", "Push was blocked by event handler: %s", push_event.reason or "Unknown reason"); + else + -- handle push errors for this node + if push_errors[push_identifier] == nil then + push_errors[push_identifier] = 0; + end + module:hook("iq-error/host/"..stanza_id, handle_push_error); + module:hook("iq-result/host/"..stanza_id, handle_push_success); + id2node[stanza_id] = node; + id2identifier[stanza_id] = push_identifier; + module:send(push_publish); + pushes = pushes + 1; end - module:hook("iq-error/host/"..stanza_id, handle_push_error); - module:hook("iq-result/host/"..stanza_id, handle_push_success); - id2node[stanza_id] = node; - id2identifier[stanza_id] = push_identifier; - module:send(push_publish); - pushes = pushes + 1; end end return pushes;