Comparison

mod_push2/mod_push2.lua @ 6266:6164849469f1

mod2_push2: suppress send if none match Rather than sending an empty notification, which is rather unhelpful
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Tue, 27 May 2025 06:21:08 -0500
parent 6233:1c16bb49f6f6
child 6267:ff7d6ee9db20
comparison
equal deleted inserted replaced
6265:22b5b744fc78 6266:6164849469f1
353 end 353 end
354 stanza._push_notify2[push_registration_id] = true; 354 stanza._push_notify2[push_registration_id] = true;
355 end 355 end
356 356
357 if send_push then 357 if send_push then
358 local any_match = false;
358 local push_notification_payload = st.stanza("notification", { xmlns = xmlns_push }) 359 local push_notification_payload = st.stanza("notification", { xmlns = xmlns_push })
359 push_notification_payload:text_tag("client", push_info.client) 360 push_notification_payload:text_tag("client", push_info.client)
360 push_notification_payload:text_tag("priority", is_voip(stanza) and "high" or (is_important(stanza, session) and "normal" or "low")) 361 push_notification_payload:text_tag("priority", is_voip(stanza) and "high" or (is_important(stanza, session) and "normal" or "low"))
361 if is_voip(stanza) then 362 if is_voip(stanza) then
362 push_notification_payload:tag("voip"):up() 363 push_notification_payload:tag("voip"):up()
409 end 410 end
410 end 411 end
411 412
412 if does_match and not sends_added[match.send] then 413 if does_match and not sends_added[match.send] then
413 sends_added[match.send] = true 414 sends_added[match.send] = true
415 any_match = true
414 if match.send == "urn:xmpp:push2:send:notify-only" then 416 if match.send == "urn:xmpp:push2:send:notify-only" then
415 -- Nothing more to add 417 -- Nothing more to add
416 elseif match.send == "urn:xmpp:push2:send:sce+rfc8291+rfc8292:0" then 418 elseif match.send == "urn:xmpp:push2:send:sce+rfc8291+rfc8292:0" then
417 add_sce_rfc8291(match, stanza, push_notification_payload) 419 add_sce_rfc8291(match, stanza, push_notification_payload)
418 add_rfc8292(match, stanza, push_notification_payload) 420 add_rfc8292(match, stanza, push_notification_payload)
420 module:log("debug", "Unkonwn send profile: " .. push_info.send) 422 module:log("debug", "Unkonwn send profile: " .. push_info.send)
421 end 423 end
422 end 424 end
423 end 425 end
424 426
425 local push_publish = st.message({ to = push_info.service, from = module.host, id = uuid.generate() }) 427 if any_match then
426 :add_child(push_notification_payload):up() 428 local push_publish = st.message({ to = push_info.service, from = module.host, id = uuid.generate() })
427 429 :add_child(push_notification_payload):up()
428 -- TODO: watch for message error replies and count or something 430
429 module:send(push_publish) 431 -- TODO: watch for message error replies and count or something
430 pushes = pushes + 1 432 module:log("info", "publish", push_publish)
433 module:send(push_publish)
434 pushes = pushes + 1
435 end
431 end 436 end
432 end 437 end
433 438
434 return pushes 439 return pushes
435 end 440 end