Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Make QuotedAttachment an explicit data type
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie-signal committed Apr 6, 2018
1 parent 6d243a4 commit 2e4aa84
Show file tree
Hide file tree
Showing 5 changed files with 1,014 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,20 @@ private byte[] createMessageContent(SignalServiceDataMessage message) throws IOE
.setAuthor(message.getQuote().get().getAuthor().getNumber())
.setText(message.getQuote().get().getText());

for (SignalServiceAttachment attachment : message.getQuote().get().getAttachments()) {
if (attachment.isPointer()) {
AttachmentPointer.Builder attachmentPointer = AttachmentPointer.newBuilder();
attachmentPointer.setContentType(attachment.asPointer().getContentType());
for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : message.getQuote().get().getAttachments()) {
DataMessage.Quote.QuotedAttachment.Builder quotedAttachment = DataMessage.Quote.QuotedAttachment.newBuilder();

if (attachment.asPointer().getFileName().isPresent()) {
attachmentPointer.setFileName(attachment.asPointer().getFileName().get());
}
quotedAttachment.setContentType(attachment.getContentType());

if (attachment.getFileName() != null) {
quotedAttachment.setFileName(attachment.getFileName());
}

quoteBuilder.addAttachments(attachmentPointer);
} else {
quoteBuilder.addAttachments(createAttachmentPointer(attachment.asStream()));
if (attachment.getThumbnail() != null) {
quotedAttachment.setThumbnail(createAttachmentPointer(attachment.getThumbnail().asStream()));
}

quoteBuilder.addAttachments(quotedAttachment);
}

builder.setQuote(quoteBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,12 @@ private SignalServiceReceiptMessage createReceiptMessage(SignalServiceEnvelope e
private SignalServiceDataMessage.Quote createQuote(SignalServiceEnvelope envelope, DataMessage content) {
if (!content.hasQuote()) return null;

List<SignalServiceAttachment> attachments = new LinkedList<>();
List<SignalServiceDataMessage.Quote.QuotedAttachment> attachments = new LinkedList<>();

for (AttachmentPointer pointer : content.getQuote().getAttachmentsList()) {
attachments.add(createAttachmentPointer(envelope, pointer));
for (DataMessage.Quote.QuotedAttachment attachment : content.getQuote().getAttachmentsList()) {
attachments.add(new SignalServiceDataMessage.Quote.QuotedAttachment(attachment.getContentType(),
attachment.getFileName(),
attachment.hasThumbnail() ? createAttachmentPointer(envelope, attachment.getThumbnail()) : null));
}

return new SignalServiceDataMessage.Quote(content.getQuote().getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ public SignalServiceDataMessage build() {
}

public static class Quote {
private final long id;
private final SignalServiceAddress author;
private final String text;
private final List<SignalServiceAttachment> attachments;
private final long id;
private final SignalServiceAddress author;
private final String text;
private final List<QuotedAttachment> attachments;

public Quote(long id, SignalServiceAddress author, String text, List<SignalServiceAttachment> attachments) {
public Quote(long id, SignalServiceAddress author, String text, List<QuotedAttachment> attachments) {
this.id = id;
this.author = author;
this.text = text;
Expand All @@ -307,10 +307,32 @@ public String getText() {
return text;
}

public List<SignalServiceAttachment> getAttachments() {
public List<QuotedAttachment> getAttachments() {
return attachments;
}

public static class QuotedAttachment {
private final String contentType;
private final String fileName;
private final SignalServiceAttachment thumbnail;

public QuotedAttachment(String contentType, String fileName, SignalServiceAttachment thumbnail) {
this.contentType = contentType;
this.fileName = fileName;
this.thumbnail = thumbnail;
}

public String getContentType() {
return contentType;
}

public String getFileName() {
return fileName;
}

public SignalServiceAttachment getThumbnail() {
return thumbnail;
}
}
}
}
Loading

0 comments on commit 2e4aa84

Please sign in to comment.