Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceAttachment#isPointer()
The following examples show how to use
org.whispersystems.signalservice.api.messages.SignalServiceAttachment#isPointer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
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.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; }
Example 2
Source File: PointerAttachment.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public static List<Attachment> forPointers(@NonNull MasterSecretUnion masterSecret, Optional<List<SignalServiceAttachment>> pointers) { List<Attachment> results = new LinkedList<>(); if (pointers.isPresent()) { for (SignalServiceAttachment pointer : pointers.get()) { if (pointer.isPointer()) { String encryptedKey = MediaKey.getEncrypted(masterSecret, pointer.asPointer().getKey()); results.add(new PointerAttachment(pointer.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_PENDING, pointer.asPointer().getSize().or(0), pointer.asPointer().getFileName().orNull(), String.valueOf(pointer.asPointer().getId()), encryptedKey, pointer.asPointer().getRelay().orNull(), pointer.asPointer().getDigest().orNull(), pointer.asPointer().getUrl().orNull(), pointer.asPointer().getVoiceNote())); } } } return results; }
Example 3
Source File: SignalServiceMessageSender.java From libsignal-service-java with GNU General Public License v3.0 | 6 votes |
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())); } else if (attachment.isPointer()) { Log.w(TAG, "Including existing attachment pointer..."); pointers.add(createAttachmentPointer(attachment.asPointer())); } } return pointers; }
Example 4
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 6 votes |
public long sendMessage(String messageText, List<String> attachments, List<String> recipients) throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException { final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText); if (attachments != null) { List<SignalServiceAttachment> attachmentStreams = Utils.getSignalServiceAttachments(attachments); // Upload attachments here, so we only upload once even for multiple recipients SignalServiceMessageSender messageSender = getMessageSender(); List<SignalServiceAttachment> attachmentPointers = new ArrayList<>(attachmentStreams.size()); for (SignalServiceAttachment attachment : attachmentStreams) { if (attachment.isStream()) { attachmentPointers.add(messageSender.uploadAttachment(attachment.asStream())); } else if (attachment.isPointer()) { attachmentPointers.add(attachment.asPointer()); } } messageBuilder.withAttachments(attachmentPointers); } return sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients)); }
Example 5
Source File: JsonAttachment.java From signald with GNU General Public License v3.0 | 5 votes |
JsonAttachment(SignalServiceAttachment attachment, String username) throws IOException, NoSuchAccountException { this.contentType = attachment.getContentType(); final SignalServiceAttachmentPointer pointer = attachment.asPointer(); if (attachment.isPointer()) { this.id = pointer.getId(); this.key = Base64.encodeBytes(pointer.getKey()); if (pointer.getSize().isPresent()) { this.size = pointer.getSize().get(); } if(pointer.getPreview().isPresent()) { this.preview = Base64.encodeBytes(pointer.getPreview().get()); } if(pointer.getDigest().isPresent()) { this.digest = Base64.encodeBytes(pointer.getDigest().get()); } this.voiceNote = pointer.getVoiceNote(); this.width = pointer.getWidth(); this.height = pointer.getHeight(); if(pointer.getCaption().isPresent()) { this.caption = pointer.getCaption().get(); } if(pointer.getBlurHash().isPresent()) { this.blurhash = pointer.getBlurHash().get(); } File file = Manager.get(username).getAttachmentFile(pointer.getId()); if(file.exists()) { this.storedFilename = file.toString(); } } }
Example 6
Source File: JsonDbusReceiveMessageHandler.java From signal-cli with GNU General Public License v3.0 | 5 votes |
static private List<String> getAttachments(SignalServiceDataMessage message, Manager m) { List<String> attachments = new ArrayList<>(); if (message.getAttachments().isPresent()) { for (SignalServiceAttachment attachment : message.getAttachments().get()) { if (attachment.isPointer()) { attachments.add(m.getAttachmentFile(attachment.asPointer().getRemoteId()).getAbsolutePath()); } } } return attachments; }
Example 7
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 5 votes |
private File retrieveContactAvatarAttachment(SignalServiceAttachment attachment, String number) throws IOException, InvalidMessageException, MissingConfigurationException { IOUtils.createPrivateDirectories(pathConfig.getAvatarsPath()); if (attachment.isPointer()) { SignalServiceAttachmentPointer pointer = attachment.asPointer(); return retrieveAttachment(pointer, getContactAvatarFile(number), false); } else { SignalServiceAttachmentStream stream = attachment.asStream(); return Utils.retrieveAttachment(stream, getContactAvatarFile(number)); } }
Example 8
Source File: Manager.java From signal-cli with GNU General Public License v3.0 | 5 votes |
private File retrieveGroupAvatarAttachment(SignalServiceAttachment attachment, byte[] groupId) throws IOException, InvalidMessageException, MissingConfigurationException { IOUtils.createPrivateDirectories(pathConfig.getAvatarsPath()); if (attachment.isPointer()) { SignalServiceAttachmentPointer pointer = attachment.asPointer(); return retrieveAttachment(pointer, getGroupAvatarFile(groupId), false); } else { SignalServiceAttachmentStream stream = attachment.asStream(); return Utils.retrieveAttachment(stream, getGroupAvatarFile(groupId)); } }
Example 9
Source File: JsonAttachment.java From signal-cli with GNU General Public License v3.0 | 5 votes |
JsonAttachment(SignalServiceAttachment attachment) { this.contentType = attachment.getContentType(); final SignalServiceAttachmentPointer pointer = attachment.asPointer(); if (attachment.isPointer()) { this.id = String.valueOf(pointer.getRemoteId()); if (pointer.getFileName().isPresent()) { this.filename = pointer.getFileName().get(); } if (pointer.getSize().isPresent()) { this.size = pointer.getSize().get(); } } }
Example 10
Source File: ReceiveMessageHandler.java From signal-cli with GNU General Public License v3.0 | 5 votes |
private void printAttachment(SignalServiceAttachment attachment) { System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")"); if (attachment.isPointer()) { final SignalServiceAttachmentPointer pointer = attachment.asPointer(); System.out.println(" Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length); System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-")); System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : "")); System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no")); System.out.println(" Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight()); File file = m.getAttachmentFile(pointer.getRemoteId()); if (file.exists()) { System.out.println(" Stored plaintext in: " + file); } } }