Changeset

6219:06621ab30be0

mod_push2: Improve session activity tracking
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Tue, 25 Mar 2025 20:54:09 -0500
parents 6218:277db84b0c95
children 6220:c83bfcc6ac0a
files mod_push2/mod_push2.lua
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_push2/mod_push2.lua	Tue Mar 25 20:43:51 2025 -0500
+++ b/mod_push2/mod_push2.lua	Tue Mar 25 20:54:09 2025 -0500
@@ -631,11 +631,6 @@
 
 		handle_notify_request(stanza, to_user, notify_push_services, event.origin, true);
 	end
-
-	-- This is a message the user has sent, indicates activity on a session
-	if event.for_user == jid.node(stanza.attr.from) and module.host == jid.host(stanza.attr.from) then
-		event.origin.last_activity = os_time()
-	end
 end
 
 module:hook("smacks-hibernation-start", hibernate_session);
@@ -644,6 +639,15 @@
 module:hook("smacks-hibernation-stanza-queued", process_smacks_stanza);
 module:hook("archive-message-added", archive_message_added);
 
+local function track_activity(event)
+	if has_body(event.stanza) or event.stanza:child_with_ns("http://jabber.org/protocol/chatstates") then
+		event.origin.last_activity = os_time()
+	end
+end
+
+module:hook("pre-message/bare", track_activity)
+module:hook("pre-message/full", track_activity)
+
 module:log("info", "Module loaded");
 function module.unload()
 	module:log("info", "Unloading module");