Comparison

mod_cloud_notify/mod_cloud_notify.lua @ 4325:9b95241c6ae5

mod_cloud_notify: Fire register and push events for integration with other modules
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Jan 2021 15:21:46 +0000
parent 4324:45dcf5d4cd6c
child 4328:5a30daf2ac02
comparison
equal deleted inserted replaced
4324:45dcf5d4cd6c 4325:9b95241c6ae5
187 node = push_node; 187 node = push_node;
188 include_payload = include_payload; 188 include_payload = include_payload;
189 options = publish_options and st.preserialize(publish_options); 189 options = publish_options and st.preserialize(publish_options);
190 timestamp = os_time(); 190 timestamp = os_time();
191 }; 191 };
192 local allow_registration = module:fire_event("cloud_notify/registration", {
193 origin = origin, stanza = stanza, push_info = push_service;
194 });
195 if allow_registration == false then
196 return true; -- Assume error reply already sent
197 end
192 push_store:set_identifier(origin.username, push_identifier, push_service); 198 push_store:set_identifier(origin.username, push_identifier, push_service);
193 local ok = push_store:flush_to_disk(origin.username); 199 local ok = push_store:flush_to_disk(origin.username);
194 if not ok then 200 if not ok then
195 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); 201 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
196 else 202 else
345 module:log("debug", "Sending %s push notification for %s@%s to %s (%s)", 351 module:log("debug", "Sending %s push notification for %s@%s to %s (%s)",
346 form_data["last-message-body"] and "important" or "unimportant", 352 form_data["last-message-body"] and "important" or "unimportant",
347 node, module.host, push_info.jid, tostring(push_info.node) 353 node, module.host, push_info.jid, tostring(push_info.node)
348 ); 354 );
349 -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish)); 355 -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish));
350 -- handle push errors for this node 356 local push_event = {
351 if push_errors[push_identifier] == nil then 357 notification_stanza = push_publish;
352 push_errors[push_identifier] = 0; 358 original_stanza = stanza;
353 end 359 node = node;
354 module:hook("iq-error/host/"..stanza_id, handle_push_error); 360 push_info = push_info;
355 module:hook("iq-result/host/"..stanza_id, handle_push_success); 361 push_summary = form_data;
356 id2node[stanza_id] = node; 362 };
357 id2identifier[stanza_id] = push_identifier; 363
358 module:send(push_publish); 364 if module:fire_event("cloud_notify/push", push_event) then
359 pushes = pushes + 1; 365 module:log("debug", "Push was blocked by event handler: %s", push_event.reason or "Unknown reason");
366 else
367 -- handle push errors for this node
368 if push_errors[push_identifier] == nil then
369 push_errors[push_identifier] = 0;
370 end
371 module:hook("iq-error/host/"..stanza_id, handle_push_error);
372 module:hook("iq-result/host/"..stanza_id, handle_push_success);
373 id2node[stanza_id] = node;
374 id2identifier[stanza_id] = push_identifier;
375 module:send(push_publish);
376 pushes = pushes + 1;
377 end
360 end 378 end
361 end 379 end
362 return pushes; 380 return pushes;
363 end 381 end
364 382