Remove unnecessary proto conversion

This commit is contained in:
AsamK 2024-09-24 17:28:24 +02:00
parent c6e93126fa
commit dbbc3fbd71
4 changed files with 8 additions and 10 deletions

View file

@ -60,14 +60,14 @@ public class AttachmentHelper {
} }
final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size()); final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size());
for (var attachment : attachments) { for (var attachment : attachments) {
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
signalServiceAttachments.add(AttachmentUtils.createAttachmentStream(attachment, uploadSpec)); signalServiceAttachments.add(AttachmentUtils.createAttachmentStream(attachment, uploadSpec));
} }
return signalServiceAttachments; return signalServiceAttachments;
} }
public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException { public SignalServiceAttachmentPointer uploadAttachment(String attachment) throws IOException, AttachmentInvalidException {
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
var attachmentStream = AttachmentUtils.createAttachmentStream(attachment, uploadSpec); var attachmentStream = AttachmentUtils.createAttachmentStream(attachment, uploadSpec);
return uploadAttachment(attachmentStream); return uploadAttachment(attachmentStream);
} }

View file

@ -113,7 +113,7 @@ public class GroupHelper {
return Optional.empty(); return Optional.empty();
} }
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec)); return Optional.of(AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty(), uploadSpec));
} }

View file

@ -750,7 +750,7 @@ public class ManagerImpl implements Manager {
final var additionalAttachments = new ArrayList<SignalServiceAttachment>(); final var additionalAttachments = new ArrayList<SignalServiceAttachment>();
if (message.messageText().length() > 2000) { if (message.messageText().length() > 2000) {
final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8); final var messageBytes = message.messageText().getBytes(StandardCharsets.UTF_8);
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes), final var streamDetails = new StreamDetails(new ByteArrayInputStream(messageBytes),
MimeUtils.LONG_TEXT, MimeUtils.LONG_TEXT,
messageBytes.length); messageBytes.length);
@ -813,7 +813,7 @@ public class ManagerImpl implements Manager {
if (streamDetails == null) { if (streamDetails == null) {
throw new InvalidStickerException("Missing local sticker file"); throw new InvalidStickerException("Missing local sticker file");
} }
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto(); final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails, final var stickerAttachment = AttachmentUtils.createAttachmentStream(streamDetails,
Optional.empty(), Optional.empty(),
uploadSpec); uploadSpec);

View file

@ -1,7 +1,6 @@
package org.asamk.signal.manager.util; package org.asamk.signal.manager.util;
import org.asamk.signal.manager.api.AttachmentInvalidException; import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.signal.protos.resumableuploads.ResumableUpload;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream; import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException; import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException;
import org.whispersystems.signalservice.api.util.StreamDetails; import org.whispersystems.signalservice.api.util.StreamDetails;
@ -14,23 +13,22 @@ import java.util.UUID;
public class AttachmentUtils { public class AttachmentUtils {
public static SignalServiceAttachmentStream createAttachmentStream( public static SignalServiceAttachmentStream createAttachmentStream(
String attachment, ResumableUpload resumableUpload String attachment, ResumableUploadSpec resumableUploadSpec
) throws AttachmentInvalidException { ) throws AttachmentInvalidException {
try { try {
final var streamDetails = Utils.createStreamDetails(attachment); final var streamDetails = Utils.createStreamDetails(attachment);
return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUpload); return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUploadSpec);
} catch (IOException e) { } catch (IOException e) {
throw new AttachmentInvalidException(attachment, e); throw new AttachmentInvalidException(attachment, e);
} }
} }
public static SignalServiceAttachmentStream createAttachmentStream( public static SignalServiceAttachmentStream createAttachmentStream(
StreamDetails streamDetails, Optional<String> name, ResumableUpload resumableUpload StreamDetails streamDetails, Optional<String> name, ResumableUploadSpec resumableUploadSpec
) throws ResumeLocationInvalidException { ) throws ResumeLocationInvalidException {
// TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
final var uploadTimestamp = System.currentTimeMillis(); final var uploadTimestamp = System.currentTimeMillis();
final var resumableUploadSpec = ResumableUploadSpec.from(resumableUpload);
return SignalServiceAttachmentStream.newStreamBuilder() return SignalServiceAttachmentStream.newStreamBuilder()
.withStream(streamDetails.getStream()) .withStream(streamDetails.getStream())
.withContentType(streamDetails.getContentType()) .withContentType(streamDetails.getContentType())