use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createAttachmentPointers.
private List<AttachmentPointer> createAttachmentPointers(Optional<List<SignalServiceAttachment>> attachments) throws IOException {
List<AttachmentPointer> pointers = new LinkedList<>();
if (!attachments.isPresent() || attachments.get().isEmpty()) {
Log.w(TAG, "No attachments present...");
return pointers;
}
for (SignalServiceAttachment attachment : attachments.get()) {
if (attachment.isStream()) {
Log.w(TAG, "Found attachment, creating pointer...");
pointers.add(createAttachmentPointer(attachment.asStream()));
}
}
return pointers;
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createMessageContent.
private byte[] createMessageContent(SignalServiceDataMessage message) throws IOException {
Content.Builder container = Content.newBuilder();
DataMessage.Builder builder = DataMessage.newBuilder();
List<AttachmentPointer> pointers = createAttachmentPointers(message.getAttachments());
if (!pointers.isEmpty()) {
builder.addAllAttachments(pointers);
}
if (message.getBody().isPresent()) {
builder.setBody(message.getBody().get());
}
if (message.getGroupInfo().isPresent()) {
builder.setGroup(createGroupContent(message.getGroupInfo().get()));
}
if (message.isEndSession()) {
builder.setFlags(DataMessage.Flags.END_SESSION_VALUE);
}
if (message.isExpirationUpdate()) {
builder.setFlags(DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE);
}
if (message.isProfileKeyUpdate()) {
builder.setFlags(DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE);
}
if (message.getExpiresInSeconds() > 0) {
builder.setExpireTimer(message.getExpiresInSeconds());
}
if (message.getProfileKey().isPresent()) {
builder.setProfileKey(ByteString.copyFrom(message.getProfileKey().get()));
}
if (message.getQuote().isPresent()) {
DataMessage.Quote.Builder quoteBuilder = DataMessage.Quote.newBuilder().setId(message.getQuote().get().getId()).setAuthor(message.getQuote().get().getAuthor().getNumber()).setText(message.getQuote().get().getText());
for (SignalServiceAttachment attachment : message.getQuote().get().getAttachments()) {
if (attachment.isPointer()) {
quoteBuilder.addAttachments(AttachmentPointer.newBuilder().setContentType(attachment.asPointer().getContentType()).setFileName(attachment.asPointer().getFileName().orNull()));
} else {
quoteBuilder.addAttachments(createAttachmentPointer(attachment.asStream()));
}
}
builder.setQuote(quoteBuilder);
}
builder.setTimestamp(message.getTimestamp());
return container.setDataMessage(builder).build().toByteArray();
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method createMessageContent.
private Content createMessageContent(SignalServiceDataMessage message) throws IOException {
Content.Builder container = Content.newBuilder();
DataMessage.Builder builder = DataMessage.newBuilder();
List<AttachmentPointer> pointers = createAttachmentPointers(message.getAttachments());
if (!pointers.isEmpty()) {
builder.addAllAttachments(pointers);
for (AttachmentPointer pointer : pointers) {
if (pointer.getAttachmentIdentifierCase() == AttachmentPointer.AttachmentIdentifierCase.CDNKEY || pointer.getCdnNumber() != 0) {
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.CDN_SELECTOR_ATTACHMENTS_VALUE, builder.getRequiredProtocolVersion()));
break;
}
}
}
if (message.getBody().isPresent()) {
builder.setBody(message.getBody().get());
}
if (message.getGroupContext().isPresent()) {
SignalServiceGroupContext groupContext = message.getGroupContext().get();
if (groupContext.getGroupV1().isPresent()) {
builder.setGroup(createGroupContent(groupContext.getGroupV1().get()));
}
if (groupContext.getGroupV2().isPresent()) {
builder.setGroupV2(createGroupContent(groupContext.getGroupV2().get()));
}
}
if (message.isEndSession()) {
builder.setFlags(DataMessage.Flags.END_SESSION_VALUE);
}
if (message.isExpirationUpdate()) {
builder.setFlags(DataMessage.Flags.EXPIRATION_TIMER_UPDATE_VALUE);
}
if (message.isProfileKeyUpdate()) {
builder.setFlags(DataMessage.Flags.PROFILE_KEY_UPDATE_VALUE);
}
if (message.getExpiresInSeconds() > 0) {
builder.setExpireTimer(message.getExpiresInSeconds());
}
if (message.getProfileKey().isPresent()) {
builder.setProfileKey(ByteString.copyFrom(message.getProfileKey().get()));
}
if (message.getQuote().isPresent()) {
DataMessage.Quote.Builder quoteBuilder = DataMessage.Quote.newBuilder().setId(message.getQuote().get().getId()).setText(message.getQuote().get().getText()).setAuthorUuid(message.getQuote().get().getAuthor().getServiceId().toString());
if (!message.getQuote().get().getMentions().isEmpty()) {
for (SignalServiceDataMessage.Mention mention : message.getQuote().get().getMentions()) {
quoteBuilder.addBodyRanges(DataMessage.BodyRange.newBuilder().setStart(mention.getStart()).setLength(mention.getLength()).setMentionUuid(mention.getAci().toString()));
}
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.MENTIONS_VALUE, builder.getRequiredProtocolVersion()));
}
for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : message.getQuote().get().getAttachments()) {
DataMessage.Quote.QuotedAttachment.Builder quotedAttachment = DataMessage.Quote.QuotedAttachment.newBuilder();
quotedAttachment.setContentType(attachment.getContentType());
if (attachment.getFileName() != null) {
quotedAttachment.setFileName(attachment.getFileName());
}
if (attachment.getThumbnail() != null) {
quotedAttachment.setThumbnail(createAttachmentPointer(attachment.getThumbnail().asStream()));
}
quoteBuilder.addAttachments(quotedAttachment);
}
builder.setQuote(quoteBuilder);
}
if (message.getSharedContacts().isPresent()) {
builder.addAllContact(createSharedContactContent(message.getSharedContacts().get()));
}
if (message.getPreviews().isPresent()) {
for (SignalServiceDataMessage.Preview preview : message.getPreviews().get()) {
DataMessage.Preview.Builder previewBuilder = DataMessage.Preview.newBuilder();
previewBuilder.setTitle(preview.getTitle());
previewBuilder.setDescription(preview.getDescription());
previewBuilder.setDate(preview.getDate());
previewBuilder.setUrl(preview.getUrl());
if (preview.getImage().isPresent()) {
if (preview.getImage().get().isStream()) {
previewBuilder.setImage(createAttachmentPointer(preview.getImage().get().asStream()));
} else {
previewBuilder.setImage(createAttachmentPointer(preview.getImage().get().asPointer()));
}
}
builder.addPreview(previewBuilder.build());
}
}
if (message.getMentions().isPresent()) {
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
builder.addBodyRanges(DataMessage.BodyRange.newBuilder().setStart(mention.getStart()).setLength(mention.getLength()).setMentionUuid(mention.getAci().toString()));
}
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.MENTIONS_VALUE, builder.getRequiredProtocolVersion()));
}
if (message.getSticker().isPresent()) {
DataMessage.Sticker.Builder stickerBuilder = DataMessage.Sticker.newBuilder();
stickerBuilder.setPackId(ByteString.copyFrom(message.getSticker().get().getPackId()));
stickerBuilder.setPackKey(ByteString.copyFrom(message.getSticker().get().getPackKey()));
stickerBuilder.setStickerId(message.getSticker().get().getStickerId());
if (message.getSticker().get().getEmoji() != null) {
stickerBuilder.setEmoji(message.getSticker().get().getEmoji());
}
if (message.getSticker().get().getAttachment().isStream()) {
stickerBuilder.setData(createAttachmentPointer(message.getSticker().get().getAttachment().asStream()));
} else {
stickerBuilder.setData(createAttachmentPointer(message.getSticker().get().getAttachment().asPointer()));
}
builder.setSticker(stickerBuilder.build());
}
if (message.isViewOnce()) {
builder.setIsViewOnce(message.isViewOnce());
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.VIEW_ONCE_VIDEO_VALUE, builder.getRequiredProtocolVersion()));
}
if (message.getReaction().isPresent()) {
DataMessage.Reaction.Builder reactionBuilder = DataMessage.Reaction.newBuilder().setEmoji(message.getReaction().get().getEmoji()).setRemove(message.getReaction().get().isRemove()).setTargetSentTimestamp(message.getReaction().get().getTargetSentTimestamp()).setTargetAuthorUuid(message.getReaction().get().getTargetAuthor().getServiceId().toString());
builder.setReaction(reactionBuilder.build());
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.REACTIONS_VALUE, builder.getRequiredProtocolVersion()));
}
if (message.getRemoteDelete().isPresent()) {
DataMessage.Delete delete = DataMessage.Delete.newBuilder().setTargetSentTimestamp(message.getRemoteDelete().get().getTargetSentTimestamp()).build();
builder.setDelete(delete);
}
if (message.getGroupCallUpdate().isPresent()) {
builder.setGroupCallUpdate(DataMessage.GroupCallUpdate.newBuilder().setEraId(message.getGroupCallUpdate().get().getEraId()));
}
if (message.getPayment().isPresent()) {
SignalServiceDataMessage.Payment payment = message.getPayment().get();
if (payment.getPaymentNotification().isPresent()) {
SignalServiceDataMessage.PaymentNotification paymentNotification = payment.getPaymentNotification().get();
DataMessage.Payment.Notification.MobileCoin.Builder mobileCoinPayment = DataMessage.Payment.Notification.MobileCoin.newBuilder().setReceipt(ByteString.copyFrom(paymentNotification.getReceipt()));
DataMessage.Payment.Notification.Builder paymentBuilder = DataMessage.Payment.Notification.newBuilder().setNote(paymentNotification.getNote()).setMobileCoin(mobileCoinPayment);
builder.setPayment(DataMessage.Payment.newBuilder().setNotification(paymentBuilder));
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.PAYMENTS_VALUE, builder.getRequiredProtocolVersion()));
}
}
if (message.getStoryContext().isPresent()) {
SignalServiceDataMessage.StoryContext storyContext = message.getStoryContext().get();
builder.setStoryContext(DataMessage.StoryContext.newBuilder().setAuthorUuid(storyContext.getAuthorAci().toString()).setSentTimestamp(storyContext.getSentTimestamp()));
}
builder.setTimestamp(message.getTimestamp());
return enforceMaxContentSize(container.setDataMessage(builder).build());
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method createAttachmentPointers.
private List<AttachmentPointer> createAttachmentPointers(Optional<List<SignalServiceAttachment>> attachments) throws IOException {
List<AttachmentPointer> pointers = new LinkedList<>();
if (!attachments.isPresent() || attachments.get().isEmpty()) {
return pointers;
}
for (SignalServiceAttachment attachment : attachments.get()) {
if (attachment.isStream()) {
Log.i(TAG, "Found attachment, creating pointer...");
pointers.add(createAttachmentPointer(attachment.asStream()));
} else if (attachment.isPointer()) {
Log.i(TAG, "Including existing attachment pointer...");
pointers.add(createAttachmentPointer(attachment.asPointer()));
}
}
return pointers;
}
Aggregations