Software / code / prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
| 6214:fe9f2c618e8a | 6215:e53f0967520c |
|---|---|
| 29 (event.reply or event.stanza):tag("feature", {var=xmlns_push}):up() | 29 (event.reply or event.stanza):tag("feature", {var=xmlns_push}):up() |
| 30 end | 30 end |
| 31 module:hook("account-disco-info", account_dico_info); | 31 module:hook("account-disco-info", account_dico_info); |
| 32 | 32 |
| 33 local function parse_match(matchel) | 33 local function parse_match(matchel) |
| 34 local match = { match = matchel.attr.profile } | 34 local match = { match = matchel.attr.profile, chats = {} } |
| 35 | |
| 36 for chatel in matchel:childtags("chat") do | |
| 37 local chat = {} | |
| 38 if chatel:get_child("mention") then | |
| 39 chat.mention = true | |
| 40 end | |
| 41 if chatel:get_child("reply") then | |
| 42 chat.reply = true | |
| 43 end | |
| 44 match.chats[chatel.attr.jid] = chat | |
| 45 end | |
| 46 | |
| 35 local send = matchel:get_child("send", "urn:xmpp:push2:send:notify-only:0") | 47 local send = matchel:get_child("send", "urn:xmpp:push2:send:notify-only:0") |
| 36 if send then | 48 if send then |
| 37 match.send = send.attr.xmlns | 49 match.send = send.attr.xmlns |
| 38 return match | 50 return match |
| 39 end | 51 end |
| 353 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") | 365 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") |
| 354 elseif match.match == "urn:xmpp:push2:match:archived-with-body" then | 366 elseif match.match == "urn:xmpp:push2:match:archived-with-body" then |
| 355 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") and has_body(stanza) | 367 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") and has_body(stanza) |
| 356 end | 368 end |
| 357 | 369 |
| 370 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)]) | |
| 371 if does_match and chat then | |
| 372 does_match = false | |
| 373 | |
| 374 local to_user, to_host = jid.split(stanza.attr.to) | |
| 375 to_user = to_user or session.username | |
| 376 to_host = to_host or module.host | |
| 377 local nick = session.rooms_joined[jid.bare(stanza.attr.from)] or to_user | |
| 378 | |
| 379 if not does_match and chat.mention then | |
| 380 local body = stanza:get_child_text("body") | |
| 381 if body and body:find(nick, 1, true) then | |
| 382 does_match = true | |
| 383 end | |
| 384 end | |
| 385 if not does_match and chat.reply then | |
| 386 local reply = stanza:get_child("reply", "urn:xmpp:reply:0") | |
| 387 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 | |
| 388 does_match = true | |
| 389 end | |
| 390 end | |
| 391 end | |
| 392 | |
| 358 if does_match and not sends_added[match.send] then | 393 if does_match and not sends_added[match.send] then |
| 359 sends_added[match.send] = true | 394 sends_added[match.send] = true |
| 360 if match.send == "urn:xmpp:push2:send:notify-only" then | 395 if match.send == "urn:xmpp:push2:send:notify-only" then |
| 361 -- Nothing more to add | 396 -- Nothing more to add |
| 362 elseif match.send == "urn:xmpp:push2:send:sce+rfc8291+rfc8292:0" then | 397 elseif match.send == "urn:xmpp:push2:send:sce+rfc8291+rfc8292:0" then |