# HG changeset patch # User Matthew Wild # Date 1629625591 -3600 # Node ID 44af84178cead47ba2169722fdba3958e3bc959f # Parent 62d41447615d6648ea1907c064841ba53fe7d959 mod_cloud_notify_encrypted: For encrypted messages, push a friendly message instead of fallback body A fix for https://github.com/snikket-im/snikket-server/issues/18 diff -r 62d41447615d -r 44af84178cea mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua --- a/mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua Sun Aug 15 12:57:00 2021 +0200 +++ b/mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua Sun Aug 22 10:46:31 2021 +0100 @@ -14,6 +14,14 @@ local xmlns_push_encrypt_aes_128_gcm = "tigase:push:encrypt:aes-128-gcm"; local xmlns_push_jingle = "tigase:push:jingle:0"; +local function detect_stanza_encryption(stanza) + local eme = stanza:get_child("encryption", "urn:xmpp:eme:0"); + if eme then return eme.attr.namespace or ""; end + -- Fallback for legacy OMEMO clients without EME + local omemo = stanza:get_child("encrypted", "eu.siacs.conversations.axolotl"); + if omemo then return "eu.siacs.conversations.axolotl"; end +end + -- https://xeps.tigase.net//docs/push-notifications/encrypt/#41-discovering-support local function account_disco_info(event) event.reply:tag("feature", {var=xmlns_push_encrypt}):up(); @@ -61,9 +69,16 @@ local push_summary = event.push_summary; local original_stanza = event.original_stanza; - local body = original_stanza:get_child_text("body"); - if body and #body > 255 then - body = body:sub(1, 255); + local is_encrypted_msg = detect_stanza_encryption(original_stanza); + local body; + if is_encrypted_msg then + -- TODO: localization + body = "You have received an encrypted message"; + else + body = original_stanza:get_child_text("body"); + if body and #body > 255 then + body = body:sub(1, 255); + end end local push_payload = {