Changeset

5800:34b46d157797

mod_measure_active_users: Exclude disabled user accounts from counts ...if usermanager exposes that API (it's in trunk, not 0.12).
author Matthew Wild <mwild1@gmail.com>
date Wed, 06 Dec 2023 15:45:44 +0000
parents 5799:5239ed05bd71
children 5801:32d662015a84
files mod_measure_active_users/mod_measure_active_users.lua
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_measure_active_users/mod_measure_active_users.lua	Wed Dec 06 15:07:09 2023 +0000
+++ b/mod_measure_active_users/mod_measure_active_users.lua	Wed Dec 06 15:45:44 2023 +0000
@@ -4,9 +4,15 @@
 local measure_d7 = module:measure("active_users_7d", "amount");
 local measure_d30 = module:measure("active_users_30d", "amount");
 
+local is_enabled = require "core.usermanager".user_is_enabled;
+
+-- Exclude disabled user accounts from the counts if usermanager supports that API
+local count_disabled = not module:get_option_boolean("measure_active_users_count_disabled", is_enabled == nil);
+
 function update_calculations()
 	module:log("debug", "Calculating active users");
-	local host_user_sessions = prosody.hosts[module.host].sessions;
+	local host = module.host;
+	local host_user_sessions = prosody.hosts[host].sessions;
 	local active_d1, active_d7, active_d30 = 0, 0, 0;
 	local now = os.time();
 	for username in store:users() do
@@ -14,7 +20,7 @@
 			-- Active now
 			active_d1, active_d7, active_d30 =
 				active_d1 + 1, active_d7 + 1, active_d30 + 1;
-		else
+		elseif count_disabled or is_enabled(username, host) then
 			local lastlog_data = store:get(username);
 			if lastlog_data then
 				-- Due to server restarts/crashes/etc. some events