Software /
code /
prosody-modules
Comparison
mod_push2/mod_push2.lua @ 6216:2f2539ce8f3b
mod_push2: implement grace period
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 24 Mar 2025 22:18:47 -0500 |
parent | 6215:e53f0967520c |
child | 6217:8ecd53452af8 |
comparison
equal
deleted
inserted
replaced
6215:e53f0967520c | 6216:2f2539ce8f3b |
---|---|
41 if chatel:get_child("reply") then | 41 if chatel:get_child("reply") then |
42 chat.reply = true | 42 chat.reply = true |
43 end | 43 end |
44 match.chats[chatel.attr.jid] = chat | 44 match.chats[chatel.attr.jid] = chat |
45 end | 45 end |
46 | |
47 match.grace = matchel:get_child_text("grace") | |
48 if match.grace then match.grace = tonumber(match.grace) end | |
46 | 49 |
47 local send = matchel:get_child("send", "urn:xmpp:push2:send:notify-only:0") | 50 local send = matchel:get_child("send", "urn:xmpp:push2:send:notify-only:0") |
48 if send then | 51 if send then |
49 match.send = send.attr.xmlns | 52 match.send = send.attr.xmlns |
50 return match | 53 return match |
365 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") | 368 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") |
366 elseif match.match == "urn:xmpp:push2:match:archived-with-body" then | 369 elseif match.match == "urn:xmpp:push2:match:archived-with-body" then |
367 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") and has_body(stanza) | 370 does_match = stanza:get_child("stana-id", "urn:xmpp:sid:0") and has_body(stanza) |
368 end | 371 end |
369 | 372 |
373 local to_user, to_host = jid.split(stanza.attr.to) | |
374 to_user = to_user or session.username | |
375 to_host = to_host or module.host | |
376 | |
377 -- If another session has recent activity within configured grace period, don't send push | |
378 if does_match and match.grace and to_host == module.host and host_sessions[to_user] then | |
379 local now = os_time() | |
380 for _, session in pairs(host_sessions[to_user].sessions) do | |
381 if session.last_activity and session.push_registration_id ~= push_registration_id and (now - session.last_activity) < match.grace then | |
382 does_match = false | |
383 end | |
384 end | |
385 end | |
386 | |
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)]) | 387 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 | 388 if does_match and chat then |
372 does_match = false | 389 does_match = false |
373 | 390 |
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 | 391 local nick = session.rooms_joined[jid.bare(stanza.attr.from)] or to_user |
378 | 392 |
379 if not does_match and chat.mention then | 393 if not does_match and chat.mention then |
380 local body = stanza:get_child_text("body") | 394 local body = stanza:get_child_text("body") |
381 if body and body:find(nick, 1, true) then | 395 if body and body:find(nick, 1, true) then |
610 end | 624 end |
611 end | 625 end |
612 | 626 |
613 handle_notify_request(stanza, to_user, notify_push_services, event.origin, true); | 627 handle_notify_request(stanza, to_user, notify_push_services, event.origin, true); |
614 end | 628 end |
629 | |
630 -- This is a message the user has sent, indicates activity on a session | |
631 if event.for_user == jid.node(stanza.attr.from) and module.host == jid.host(stanza.attr.from) then | |
632 event.origin.last_activity = os_time() | |
633 end | |
615 end | 634 end |
616 | 635 |
617 module:hook("smacks-hibernation-start", hibernate_session); | 636 module:hook("smacks-hibernation-start", hibernate_session); |
618 module:hook("smacks-hibernation-end", restore_session); | 637 module:hook("smacks-hibernation-end", restore_session); |
619 module:hook("smacks-ack-delayed", ack_delayed); | 638 module:hook("smacks-ack-delayed", ack_delayed); |