changeset 5757:08a635862201

mod_audit: Update command to handle storing JIDs instead of only usernames
author Kim Alvefur <zash@zash.se>
date Sat, 02 Dec 2023 11:48:19 +0100
parents e199f33f7a2e
children 32bc648e3892
files mod_audit/mod_audit.lua
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_audit/mod_audit.lua	Sat Dec 02 11:18:57 2023 +0100
+++ b/mod_audit/mod_audit.lua	Sat Dec 02 11:48:19 2023 +0100
@@ -172,7 +172,8 @@
 	 });
 
 	module:log("debug", "arg = %q", arg);
-	local query_user, host = jid.prepped_split(arg[1]);
+	local query_jid = jid.prep(arg[1]);
+	local host = jid.host(query_jid);
 
 	if arg.prune then
 		local sm = require "core.storagemanager";
@@ -201,14 +202,16 @@
 	local c = 0;
 
 	if arg.global then
-		if query_user then
+		if jid.node(query_jid) then
 			print("WW: Specifying a user account is incompatible with --global. Showing only global events.");
 		end
-		query_user = "@";
+		query_jid = "@";
+	elseif host == query_jid then
+		query_jid = "@";
 	end
 
 	local results, err = store:find(nil, {
-		with = query_user;
+		with = query_jid;
 		limit = arg.limit and tonumber(arg.limit) or nil;
 		reverse = true;
 	})
@@ -223,7 +226,7 @@
 		{ title = "Event", key = "event_type", width = "2p" };
 	};
 
-	if arg.show_user ~= false and (not arg.global and not query_user) or arg.show_user then
+	if arg.show_user ~= false and (not arg.global and not query_jid) or arg.show_user then
 		table.insert(colspec, {
 			title = "User", key = "username", width = "2p",
 			mapper = function (user)