Skip to content

Commit

Permalink
Remove unnecessary proto conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Sep 24, 2024
1 parent c6e9312 commit dbbc3fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ private List<SignalServiceAttachmentStream> createAttachmentStreams(List<String>
}
final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size());
for (var attachment : attachments) {
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec().toProto();
final var uploadSpec = dependencies.getMessageSender().getResumableUploadSpec();
signalServiceAttachments.add(AttachmentUtils.createAttachmentStream(attachment, uploadSpec));
}
return signalServiceAttachments;
}

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);
return uploadAttachment(attachmentStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(Group
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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ private void applyMessage(
final var additionalAttachments = new ArrayList<SignalServiceAttachment>();
if (message.messageText().length() > 2000) {
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),
MimeUtils.LONG_TEXT,
messageBytes.length);
Expand Down Expand Up @@ -813,7 +813,7 @@ private void applyMessage(
if (streamDetails == null) {
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,
Optional.empty(),
uploadSpec);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.asamk.signal.manager.util;

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.push.exceptions.ResumeLocationInvalidException;
import org.whispersystems.signalservice.api.util.StreamDetails;
Expand All @@ -14,23 +13,22 @@
public class AttachmentUtils {

public static SignalServiceAttachmentStream createAttachmentStream(
String attachment, ResumableUpload resumableUpload
String attachment, ResumableUploadSpec resumableUploadSpec
) throws AttachmentInvalidException {
try {
final var streamDetails = Utils.createStreamDetails(attachment);

return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUpload);
return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUploadSpec);
} catch (IOException e) {
throw new AttachmentInvalidException(attachment, e);
}
}

public static SignalServiceAttachmentStream createAttachmentStream(
StreamDetails streamDetails, Optional<String> name, ResumableUpload resumableUpload
StreamDetails streamDetails, Optional<String> name, ResumableUploadSpec resumableUploadSpec
) throws ResumeLocationInvalidException {
// TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
final var uploadTimestamp = System.currentTimeMillis();
final var resumableUploadSpec = ResumableUploadSpec.from(resumableUpload);
return SignalServiceAttachmentStream.newStreamBuilder()
.withStream(streamDetails.getStream())
.withContentType(streamDetails.getContentType())
Expand Down

0 comments on commit dbbc3fb

Please sign in to comment.