comparison mod_cloud_notify/mod_cloud_notify.lua @ 4332:7a5ca4b285cb

mod_cloud_notify: Some restructuring to allow direct access to notification element within push event
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 Jan 2021 15:00:41 +0000
parents 5a30daf2ac02
children 31afa4f314cc
comparison
equal deleted inserted replaced
4331:2e355540f8c8 4332:7a5ca4b285cb
321 end 321 end
322 322
323 if send_push then 323 if send_push then
324 -- construct push stanza 324 -- construct push stanza
325 local stanza_id = hashes.sha256(random.bytes(8), true); 325 local stanza_id = hashes.sha256(random.bytes(8), true);
326 local push_publish = st.iq({ to = push_info.jid, from = module.host, type = "set", id = stanza_id }) 326 local push_notification_payload = st.stanza("notification", { xmlns = xmlns_push });
327 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
328 :tag("publish", { node = push_info.node })
329 :tag("item")
330 :tag("notification", { xmlns = xmlns_push });
331 local form_data = { 327 local form_data = {
332 -- hardcode to 1 because other numbers are just meaningless (the XEP does not specify *what exactly* to count) 328 -- hardcode to 1 because other numbers are just meaningless (the XEP does not specify *what exactly* to count)
333 ["message-count"] = "1"; 329 ["message-count"] = "1";
334 }; 330 };
335 if stanza and include_sender then 331 if stanza and include_sender then
338 if stanza and include_body then 334 if stanza and include_body then
339 form_data["last-message-body"] = stanza:get_child_text("body"); 335 form_data["last-message-body"] = stanza:get_child_text("body");
340 elseif stanza and dummy_body and is_important(stanza) then 336 elseif stanza and dummy_body and is_important(stanza) then
341 form_data["last-message-body"] = tostring(dummy_body); 337 form_data["last-message-body"] = tostring(dummy_body);
342 end 338 end
343 push_publish:add_child(push_form:form(form_data)); 339
344 push_publish:up(); -- / notification 340 local push_publish = st.iq({ to = push_info.jid, from = module.host, type = "set", id = stanza_id })
345 push_publish:up(); -- / publish 341 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
346 push_publish:up(); -- / pubsub 342 :tag("publish", { node = push_info.node })
343 :tag("item")
344 :add_child(push_notification_payload)
345 :add_child(push_form:form(form_data))
346 :up()
347 :up();
348
347 if push_info.options then 349 if push_info.options then
348 push_publish:tag("publish-options"):add_child(st.deserialize(push_info.options)); 350 push_publish:tag("publish-options"):add_child(st.deserialize(push_info.options));
349 end 351 end
350 -- send out push 352 -- send out push
351 module:log("debug", "Sending %s push notification for %s@%s to %s (%s)", 353 module:log("debug", "Sending %s push notification for %s@%s to %s (%s)",
353 node, module.host, push_info.jid, tostring(push_info.node) 355 node, module.host, push_info.jid, tostring(push_info.node)
354 ); 356 );
355 -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish)); 357 -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish));
356 local push_event = { 358 local push_event = {
357 notification_stanza = push_publish; 359 notification_stanza = push_publish;
360 notification_payload = push_notification_payload;
358 original_stanza = stanza; 361 original_stanza = stanza;
359 node = node; 362 node = node;
360 push_info = push_info; 363 push_info = push_info;
361 push_summary = form_data; 364 push_summary = form_data;
362 important = not not form_data["last-message-body"]; 365 important = not not form_data["last-message-body"];