# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1737112745 0
# Node ID ddb0fac151acca3ab16e07fee64c87144f4aaab4
# Parent  bcad6baa4fc3fed54a272cf47a5632ff1225221c
mod_anti_spam: Don't consider pre-approved contacts as strangers

Also fixes a traceback introduced in the previous commit.

diff -r bcad6baa4fc3 -r ddb0fac151ac mod_anti_spam/mod_anti_spam.lua
--- a/mod_anti_spam/mod_anti_spam.lua	Fri Jan 17 10:20:00 2025 +0100
+++ b/mod_anti_spam/mod_anti_spam.lua	Fri Jan 17 11:19:05 2025 +0000
@@ -4,8 +4,7 @@
 local set = require "util.set";
 local sha256 = require "util.hashes".sha256;
 local st = require"util.stanza";
-local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
-local is_user_subscribed = require "core.rostermanager".is_user_subscribed;
+local rm = require "core.rostermanager";
 local full_sessions = prosody.full_sessions;
 
 local user_exists = require "core.usermanager".user_exists;
@@ -69,9 +68,10 @@
 	if to_session then return false; end
 
 	if not (
-		is_contact_subscribed(to_user, to_host, from_jid) or
-		is_user_subscribed(to_user, to_host, from_jid) or
-		is_contact_pending_out(to_user, to_host, from_jid)
+		rm.is_contact_subscribed(to_user, to_host, from_jid) or
+		rm.is_user_subscribed(to_user, to_host, from_jid) or
+		rm.is_contact_pending_out(to_user, to_host, from_jid) or
+		rm.is_contact_preapproved(to_user, to_host, from_jid)
 	) then
 		local from_user, from_host = jid_split(from_jid);
 
@@ -82,7 +82,7 @@
 		if to_resource and stanza.attr.type == "groupchat" then
 			return false; -- Pass through group chat messages
 		end
-		if is_contact_subscribed(to_user, to_host, from_host) then
+		if rm.is_contact_subscribed(to_user, to_host, from_host) then
 			-- If you have the sending domain in your roster,
 			-- allow through (probably a gateway)
 			return false;