Don't assume presence of phone numbers for spam reports

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2026-08-03 09:39:44 -04:00
1 parent a3d01a94d4
commit e60daa75a8
5 files changed
+8 -7

No files matched your search

@@ -42,7 +42,7 @@ public class ReportedMessageMetricsListener implements ReportedMessageListener {
return;
}
final String sourceCountryCode = sourceNumber.map(Util::getCountryCode).orElse("n/a");
final String sourceCountryCode = sourceNumber.map(Util::getCountryCode).orElse(Util.COUNTRY_CODE_NOT_APPLICABLE);
Metrics.counter(REPORTED_COUNTER_NAME, COUNTRY_CODE_TAG_NAME, sourceCountryCode).increment();
@@ -117,9 +117,7 @@ public class ReportMessageManager {
return rateLimitCluster.withCluster(
connection ->
Math.max(
account.getPhoneNumberIdentifierOptional()
.map(pni -> connection.sync().pfcount(getReportedSenderPniKey(pni)).intValue())
.orElse(0),
account.getPhoneNumberIdentifierOptional().map(pni -> connection.sync().pfcount(getReportedSenderPniKey(pni)).intValue()).orElse(0),
connection.sync().pfcount(getReportedSenderAciKey(account.getAccountIdentifier())).intValue()));
} catch (final RedisException e) {
return 0;
@@ -10,5 +10,6 @@ import java.util.UUID;
public interface ReportedMessageListener {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
void handleMessageReported(Optional<String> sourceNumber, UUID messageGuid, UUID reporterUuid, Optional<byte[]> reportSpamToken, boolean sourceAccountDeleted);
}
@@ -33,6 +33,9 @@ public class Util {
public static final Runnable NOOP = () -> {};
public static final String COUNTRY_CODE_NOT_APPLICABLE = "n/a";
public static final String REGION_NOT_APPLICABLE = "n/a";
// Use `CompletableFuture#thenApply(ASYNC_EMPTY_RESPONSE) to convert futures to
// CompletableFuture<Response> instead of using NOOP to convert them to CompletableFuture<Void>
// for jersey controllers; https://github.com/eclipse-ee4j/jersey/issues/3901 causes controllers
@@ -84,7 +87,7 @@ public class Util {
}
public static String getCountryCode(final Account account) {
return account.getNumberOptional().map(Util::getCountryCode).orElse("n/a");
return account.getNumberOptional().map(Util::getCountryCode).orElse(COUNTRY_CODE_NOT_APPLICABLE);
}
public static String getCountryCode(final String number) {
@@ -96,7 +99,7 @@ public class Util {
}
public static String getRegion(final Account account) {
return account.getNumberOptional().map(Util::getRegion).orElse("n/a");
return account.getNumberOptional().map(Util::getRegion).orElse(REGION_NOT_APPLICABLE);
}
public static String getRegion(final String number) {
@@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;