Add constant for MAX_MESSAGE_BODY_SIZE

This commit is contained in:
AsamK 2024-09-29 09:43:05 +02:00
parent 304c44064d
commit 7f1fc932ad
2 changed files with 4 additions and 2 deletions

View file

@ -20,6 +20,7 @@ public class ServiceConfig {
public static final int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024; public static final int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024;
public static final long MAX_ENVELOPE_SIZE = 0; public static final long MAX_ENVELOPE_SIZE = 0;
public static final int MAX_MESSAGE_BODY_SIZE = 2000;
public static final long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE = 10 * 1024 * 1024; public static final long AVATAR_DOWNLOAD_FAILSAFE_MAX_SIZE = 10 * 1024 * 1024;
public static final boolean AUTOMATIC_NETWORK_RETRY = true; public static final boolean AUTOMATIC_NETWORK_RETRY = true;
public static final int GROUP_MAX_SIZE = 1001; public static final int GROUP_MAX_SIZE = 1001;

View file

@ -68,6 +68,7 @@ import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.api.UsernameLinkUrl; import org.asamk.signal.manager.api.UsernameLinkUrl;
import org.asamk.signal.manager.api.UsernameStatus; import org.asamk.signal.manager.api.UsernameStatus;
import org.asamk.signal.manager.api.VerificationMethodNotAvailableException; import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig; import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.helper.AccountFileUpdater; import org.asamk.signal.manager.helper.AccountFileUpdater;
import org.asamk.signal.manager.helper.Context; import org.asamk.signal.manager.helper.Context;
@ -748,7 +749,7 @@ public class ManagerImpl implements Manager {
final SignalServiceDataMessage.Builder messageBuilder, final Message message final SignalServiceDataMessage.Builder messageBuilder, final Message message
) throws AttachmentInvalidException, IOException, UnregisteredRecipientException, InvalidStickerException { ) throws AttachmentInvalidException, IOException, UnregisteredRecipientException, InvalidStickerException {
final var additionalAttachments = new ArrayList<SignalServiceAttachment>(); final var additionalAttachments = new ArrayList<SignalServiceAttachment>();
if (message.messageText().length() > 2000) { if (message.messageText().length() > ServiceConfig.MAX_MESSAGE_BODY_SIZE) {
final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8); final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8);
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes), final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes),
@ -757,7 +758,7 @@ public class ManagerImpl implements Manager {
final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails, final var textAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
Optional.empty(), Optional.empty(),
uploadSpec); uploadSpec);
messageBuilder.withBody(message.messageText().substring(0, 2000)); messageBuilder.withBody(message.messageText().substring(0, ServiceConfig.MAX_MESSAGE_BODY_SIZE));
additionalAttachments.add(context.getAttachmentHelper().uploadAttachment(textAttachment)); additionalAttachments.add(context.getAttachmentHelper().uploadAttachment(textAttachment));
} else { } else {
messageBuilder.withBody(message.messageText()); messageBuilder.withBody(message.messageText());