Software /
code /
prosody-modules
Changeset
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 | 4331:2e355540f8c8 |
children | 4333:97f369745ec7 |
files | mod_cloud_notify/mod_cloud_notify.lua |
diffstat | 1 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_cloud_notify/mod_cloud_notify.lua Wed Jan 13 14:19:20 2021 +0000 +++ b/mod_cloud_notify/mod_cloud_notify.lua Wed Jan 13 15:00:41 2021 +0000 @@ -323,11 +323,7 @@ if send_push then -- construct push stanza local stanza_id = hashes.sha256(random.bytes(8), true); - local push_publish = st.iq({ to = push_info.jid, from = module.host, type = "set", id = stanza_id }) - :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) - :tag("publish", { node = push_info.node }) - :tag("item") - :tag("notification", { xmlns = xmlns_push }); + local push_notification_payload = st.stanza("notification", { xmlns = xmlns_push }); local form_data = { -- hardcode to 1 because other numbers are just meaningless (the XEP does not specify *what exactly* to count) ["message-count"] = "1"; @@ -340,10 +336,16 @@ elseif stanza and dummy_body and is_important(stanza) then form_data["last-message-body"] = tostring(dummy_body); end - push_publish:add_child(push_form:form(form_data)); - push_publish:up(); -- / notification - push_publish:up(); -- / publish - push_publish:up(); -- / pubsub + + local push_publish = st.iq({ to = push_info.jid, from = module.host, type = "set", id = stanza_id }) + :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) + :tag("publish", { node = push_info.node }) + :tag("item") + :add_child(push_notification_payload) + :add_child(push_form:form(form_data)) + :up() + :up(); + if push_info.options then push_publish:tag("publish-options"):add_child(st.deserialize(push_info.options)); end @@ -355,6 +357,7 @@ -- module:log("debug", "PUSH STANZA: %s", tostring(push_publish)); local push_event = { notification_stanza = push_publish; + notification_payload = push_notification_payload; original_stanza = stanza; node = node; push_info = push_info;