Changeset

6064:765e0235c202

mod_report_tracker: Add trait for reported accounts, for mod_report_affiliations
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 Nov 2024 14:06:16 +0000
parents 6063:b04518fa0987
children 6065:7d4386cc73d3
files mod_report_tracker/mod_report_tracker.lua
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_report_tracker/mod_report_tracker.lua	Mon Nov 25 13:12:20 2024 +0000
+++ b/mod_report_tracker/mod_report_tracker.lua	Mon Nov 25 14:06:16 2024 +0000
@@ -1,12 +1,14 @@
 local um = require "core.usermanager";
+local cache = require "util.cache";
 local jid = require "util.jid";
-
 local trusted_reporters = module:get_option_inherited_set("trusted_reporters", {});
 
 local reports_received = module:open_store("reports_received");
 
 local xmlns_reporting = "urn:xmpp:reporting:1";
 
+local reported_users = cache.new(256);
+
 local function is_trusted_reporter(reporter_jid)
 	return trusted_reporters:contains(reporter_jid);
 end
@@ -54,6 +56,7 @@
 		end
 
 		reports_received:set(reported_user, reporter_jid, current_reports);
+		reported_users:set(reported_user, true);
 
 		module:log("info", "Received abuse report about <%s> from <%s>", reported_jid, reporter_jid);
 
@@ -71,3 +74,20 @@
 end
 
 module:hook("message/host", handle_report);
+
+module:add_item("account-trait", {
+	name = "reported-by-trusted-server";
+	prob_bad_true = 0.80;
+	prob_bad_false = 0.50;
+});
+
+module:hook("get-account-traits", function (event)
+	local username = event.username;
+	local reported = reported_users:get(username);
+	if reported == nil then
+		-- Check storage, update cache
+		reported = not not reports_received:get(username);
+		reported_users:set(username, reported);
+	end
+	event.traits["reported-by-trusted-server"] = reported;
+end);