Software /
code /
prosody-modules
Diff
mod_push2/mod_push2.lua @ 6215:e53f0967520c
mod_push: Allow filtering pushes for particular chats
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 24 Mar 2025 13:01:05 -0500 |
parent | 6214:fe9f2c618e8a |
child | 6216:2f2539ce8f3b |
line wrap: on
line diff
--- a/mod_push2/mod_push2.lua Mon Mar 24 09:28:25 2025 -0500 +++ b/mod_push2/mod_push2.lua Mon Mar 24 13:01:05 2025 -0500 @@ -31,7 +31,19 @@ module:hook("account-disco-info", account_dico_info); local function parse_match(matchel) - local match = { match = matchel.attr.profile } + local match = { match = matchel.attr.profile, chats = {} } + + for chatel in matchel:childtags("chat") do + local chat = {} + if chatel:get_child("mention") then + chat.mention = true + end + if chatel:get_child("reply") then + chat.reply = true + end + match.chats[chatel.attr.jid] = chat + end + local send = matchel:get_child("send", "urn:xmpp:push2:send:notify-only:0") if send then match.send = send.attr.xmlns @@ -355,6 +367,29 @@ does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") and has_body(stanza) end + local chat = match.chats and (match.chats[stanza.attr.from] or match.chats[jid.bare(stanza.attr.from)] or match.chats[jid.host(stanza.attr.from)]) + if does_match and chat then + does_match = false + + local to_user, to_host = jid.split(stanza.attr.to) + to_user = to_user or session.username + to_host = to_host or module.host + local nick = session.rooms_joined[jid.bare(stanza.attr.from)] or to_user + + if not does_match and chat.mention then + local body = stanza:get_child_text("body") + if body and body:find(nick, 1, true) then + does_match = true + end + end + if not does_match and chat.reply then + local reply = stanza:get_child("reply", "urn:xmpp:reply:0") + if reply and (reply.attr.to == to_user.."@"..to_host or (jid.bare(reply.attr.to) == jid.bare(stanza.attr.from) and jid.resource(reply.attr.to) == nick)) then + does_match = true + end + end + end + if does_match and not sends_added[match.send] then sends_added[match.send] = true if match.send == "urn:xmpp:push2:send:notify-only" then