Software /
code /
prosody-modules
Changeset
6213:811bd0872682
mod_push2: Do not push MUC reflections
Messages from myself to a MUC come back and should not get pushed.
MUC subjects don't have a body so seperately checking for those is not needed.
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 24 Mar 2025 08:53:36 -0500 |
parents | 6212:051974b4c900 |
children | 6214:fe9f2c618e8a |
files | mod_push2/mod_push2.lua |
diffstat | 1 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_push2/mod_push2.lua Mon Mar 24 08:51:30 2025 -0500 +++ b/mod_push2/mod_push2.lua Mon Mar 24 08:53:36 2025 -0500 @@ -9,6 +9,8 @@ local crypto = require "util.crypto"; local jwt = require "util.jwt"; +pcall(function() module:depends("track_muc_joins") end) + local xmlns_push = "urn:xmpp:push2:0"; -- configuration @@ -156,7 +158,7 @@ end -- is this push a high priority one -local function is_important(stanza) +local function is_important(stanza, session) local is_voip_stanza, urgent_reason = is_voip(stanza) if is_voip_stanza then return true; end @@ -177,9 +179,13 @@ -- carbon copied outgoing messages are not important if carbon and stanza_direction == "out" then return false; end - -- groupchat subjects are not important here - if st_type == "groupchat" and stanza:get_child_text("subject") then - return false + -- groupchat reflections are not important here + if st_type == "groupchat" and session and session.rooms_joined then + local muc = jid.bare(stanza.attr.from) + local from_nick = jid.resource(stanza.attr.from) + if from_nick == session.rooms_joined[muc] then + return false + end end -- empty bodies are not important @@ -295,12 +301,12 @@ push_notification_payload:text_tag("jwt", signer(payload), { key = base64.encode(public_key) }) end -local function handle_notify_request(stanza, node, user_push_services, log_push_decline) +local function handle_notify_request(stanza, node, user_push_services, session, log_push_decline) local pushes = 0; if not #user_push_services then return pushes end local notify_push_services = {}; - if is_important(stanza) then + if is_important(stanza, session) then notify_push_services = user_push_services else for identifier, push_info in pairs(user_push_services) do @@ -330,7 +336,7 @@ if send_push then local push_notification_payload = st.stanza("notification", { xmlns = xmlns_push }) push_notification_payload:text_tag("client", push_info.client) - push_notification_payload:text_tag("priority", is_voip(stanza) and "high" or (is_important(stanza) and "normal" or "low")) + push_notification_payload:text_tag("priority", is_voip(stanza) and "high" or (is_important(stanza, session) and "normal" or "low")) if is_voip(stanza) then push_notification_payload:tag("voip"):up() end @@ -341,7 +347,7 @@ if match.match == "urn:xmpp:push2:match:all" then does_match = true elseif match.match == "urn:xmpp:push2:match:important" then - does_match = is_important(stanza) + does_match = is_important(stanza, session) elseif match.match == "urn:xmpp:push2:match:archived" then does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") elseif match.match == "urn:xmpp:push2:match:archived-with-body" then @@ -385,7 +391,7 @@ module:hook("message/offline/handle", function(event) local node, user_push_services = get_push_settings(event.stanza, event.origin); module:log("debug", "Invoking handle_notify_request() for offline stanza"); - handle_notify_request(event.stanza, node, user_push_services, true); + handle_notify_request(event.stanza, node, user_push_services, event.origin, true); end, 1); -- publish on bare groupchat @@ -403,7 +409,7 @@ end end - handle_notify_request(event.stanza, node, notify_push_services, true); + handle_notify_request(event.stanza, node, notify_push_services, event.origin, true); end, 1); local function process_stanza_queue(queue, session, queue_type) @@ -416,14 +422,14 @@ local node, all_push_services = get_push_settings(stanza, session) local user_push_services = {[session.push_registration_id] = all_push_services[session.push_registration_id]} local stanza_type = "unimportant"; - if is_important(stanza) then stanza_type = "important"; end + if is_important(stanza, session) then stanza_type = "important"; end if not notified[stanza_type] then -- only notify if we didn't try to push for this stanza type already - if handle_notify_request(stanza, node, user_push_services, false) ~= 0 then + if handle_notify_request(stanza, node, user_push_services, session, false) ~= 0 then if session.hibernating and not session.first_hibernated_push then -- if the message was important -- then record the time of first push in the session for the smack module which will extend its hibernation -- timeout based on the value of session.first_hibernated_push - if is_important(stanza) then + if is_important(stanza, session) then session.first_hibernated_push = os_time(); -- check for prosody 0.12 mod_smacks if session.hibernating_watchdog and session.original_smacks_callback and session.original_smacks_timeout then @@ -568,7 +574,7 @@ end end - handle_notify_request(stanza, to_user, notify_push_services, true); + handle_notify_request(stanza, to_user, notify_push_services, event.origin, true); end end