org.whispersystems.signalservice.api.messages.SignalServiceAttachment Java Examples

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceAttachment. 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: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void sendUpdate(SignalServiceMessageSender messageSender, File contactsFile, boolean complete)
    throws IOException, UntrustedIdentityException, NetworkException
{
  if (contactsFile.length() > 0) {
    FileInputStream               contactsFileStream = new FileInputStream(contactsFile);
    SignalServiceAttachmentStream attachmentStream   = SignalServiceAttachment.newStreamBuilder()
                                                                              .withStream(contactsFileStream)
                                                                              .withContentType("application/octet-stream")
                                                                              .withLength(contactsFile.length())
                                                                              .build();

    try {
      messageSender.sendMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, complete)),
                                UnidentifiedAccessUtil.getAccessForSync(context));
    } catch (IOException ioe) {
      throw new NetworkException(ioe);
    }
  }
}
 
Example #2
Source File: JsonDataMessage.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
JsonDataMessage(SignalServiceDataMessage dataMessage) {
    this.timestamp = dataMessage.getTimestamp();
    if (dataMessage.getGroupContext().isPresent() && dataMessage.getGroupContext().get().getGroupV1().isPresent()) {
        SignalServiceGroup groupInfo = dataMessage.getGroupContext().get().getGroupV1().get();
        this.groupInfo = new JsonGroupInfo(groupInfo);
    }
    if (dataMessage.getBody().isPresent()) {
        this.message = dataMessage.getBody().get();
    }
    this.expiresInSeconds = dataMessage.getExpiresInSeconds();
    if (dataMessage.getAttachments().isPresent()) {
        this.attachments = new ArrayList<>(dataMessage.getAttachments().get().size());
        for (SignalServiceAttachment attachment : dataMessage.getAttachments().get()) {
            this.attachments.add(new JsonAttachment(attachment));
        }
    } else {
        this.attachments = new ArrayList<>();
    }
}
 
Example #3
Source File: PushSendJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
protected SignalServiceAttachment getAttachmentFor(Attachment attachment) {
  try {
    if (attachment.getDataUri() == null || attachment.getSize() == 0) throw new IOException("Assertion failed, outgoing attachment has no data!");
    InputStream is = PartAuthority.getAttachmentStream(context, attachment.getDataUri());
    return SignalServiceAttachment.newStreamBuilder()
                                  .withStream(is)
                                  .withContentType(attachment.getContentType())
                                  .withLength(attachment.getSize())
                                  .withFileName(attachment.getFileName())
                                  .withVoiceNote(attachment.isVoiceNote())
                                  .withWidth(attachment.getWidth())
                                  .withHeight(attachment.getHeight())
                                  .withCaption(attachment.getCaption())
                                  .withListener((total, progress) -> EventBus.getDefault().postSticky(new PartProgressEvent(attachment, PartProgressEvent.Type.NETWORK, total, progress)))
                                  .build();
  } catch (IOException ioe) {
    Log.w(TAG, "Couldn't open attachment", ioe);
  }
  return null;
}
 
Example #4
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private List<Preview> createPreviews(DataMessage content) {
  if (content.getPreviewCount() <= 0) return null;

  List<Preview> results = new LinkedList<>();

  for (DataMessage.Preview preview : content.getPreviewList()) {
    SignalServiceAttachment attachment = null;

    if (preview.hasImage()) {
      attachment = createAttachmentPointer(preview.getImage());
    }

    results.add(new Preview(preview.getUrl(),
                            preview.getTitle(),
                            Optional.fromNullable(attachment)));
  }

  return results;
}
 
Example #5
Source File: PointerAttachment.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source File: SignalServiceSyncMessage.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceSyncMessage(Optional<SentTranscriptMessage>   sent,
                                 Optional<ContactsMessage>         contacts,
                                 Optional<SignalServiceAttachment> groups,
                                 Optional<BlockedListMessage>      blockedList,
                                 Optional<RequestMessage>          request,
                                 Optional<List<ReadMessage>>       reads,
                                 Optional<VerifiedMessage>         verified,
                                 Optional<ConfigurationMessage>    configuration)
{
  this.sent          = sent;
  this.contacts      = contacts;
  this.groups        = groups;
  this.blockedList   = blockedList;
  this.request       = request;
  this.reads         = reads;
  this.verified      = verified;
  this.configuration = configuration;
}
 
Example #8
Source File: PushSendJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
protected Optional<SignalServiceDataMessage.Sticker> getStickerFor(OutgoingMediaMessage message) {
  Attachment stickerAttachment = Stream.of(message.getAttachments()).filter(Attachment::isSticker).findFirst().orElse(null);

  if (stickerAttachment == null) {
    return Optional.absent();
  }

  try {
    byte[]                  packId     = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackId());
    byte[]                  packKey    = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackKey());
    int                     stickerId  = stickerAttachment.getSticker().getStickerId();
    SignalServiceAttachment attachment = getAttachmentPointerFor(stickerAttachment);

    return Optional.of(new SignalServiceDataMessage.Sticker(packId, packKey, stickerId, attachment));
  } catch (IOException e) {
    Log.w(TAG, "Failed to decode sticker id/key", e);
    return Optional.absent();
  }
}
 
Example #9
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
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 #10
Source File: SignalServiceSyncMessage.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static SignalServiceSyncMessage forRead(ReadMessage read) {
  List<ReadMessage> reads = new LinkedList<>();
  reads.add(read);

  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.of(reads),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent(),
                                      Optional.<KeysMessage>absent(),
                                      Optional.<MessageRequestResponseMessage>absent());
}
 
Example #11
Source File: PointerAttachment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public static Optional<Attachment> forPointer(SignalServiceDataMessage.Quote.QuotedAttachment pointer) {
  SignalServiceAttachment thumbnail = pointer.getThumbnail();

  return Optional.of(new PointerAttachment(pointer.getContentType(),
                                           AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
                                           thumbnail != null ? thumbnail.asPointer().getSize().or(0) : 0,
                                           pointer.getFileName(),
                                           thumbnail != null ? thumbnail.asPointer().getCdnNumber() : 0,
                                           thumbnail != null ? thumbnail.asPointer().getRemoteId().toString() : "0",
                                           thumbnail != null && thumbnail.asPointer().getKey() != null ? Base64.encodeBytes(thumbnail.asPointer().getKey()) : null,
                                           null,
                                           thumbnail != null ? thumbnail.asPointer().getDigest().orNull() : null,
                                           null,
                                           false,
                                           thumbnail != null ? thumbnail.asPointer().getWidth() : 0,
                                           thumbnail != null ? thumbnail.asPointer().getHeight() : 0,
                                           thumbnail != null ? thumbnail.asPointer().getUploadTimestamp() : 0,
                                           thumbnail != null ? thumbnail.asPointer().getCaption().orNull() : null,
                                           null,
                                           null));
}
 
Example #12
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
private SignalServiceSyncMessage(Optional<SentTranscriptMessage>             sent,
                                 Optional<ContactsMessage>                   contacts,
                                 Optional<SignalServiceAttachment>           groups,
                                 Optional<BlockedListMessage>                blockedList,
                                 Optional<RequestMessage>                    request,
                                 Optional<List<ReadMessage>>                 reads,
                                 Optional<ViewOnceOpenMessage>               viewOnceOpen,
                                 Optional<VerifiedMessage>                   verified,
                                 Optional<ConfigurationMessage>              configuration,
                                 Optional<List<StickerPackOperationMessage>> stickerPackOperations,
                                 Optional<FetchType>                         fetchType)
{
  this.sent                  = sent;
  this.contacts              = contacts;
  this.groups                = groups;
  this.blockedList           = blockedList;
  this.request               = request;
  this.reads                 = reads;
  this.viewOnceOpen          = viewOnceOpen;
  this.verified              = verified;
  this.configuration         = configuration;
  this.stickerPackOperations = stickerPackOperations;
  this.fetchType             = fetchType;
}
 
Example #13
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
public static SignalServiceSyncMessage forRead(ReadMessage read) {
  List<ReadMessage> reads = new LinkedList<>();
  reads.add(read);

  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.of(reads),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #14
Source File: Xkcd.java    From signal-bot with GNU Affero General Public License v3.0 5 votes vote down vote up
private void sendXkcd(User sender, Group group, String id) throws IOException {
	Map<String, Object> info = getData(id + "/info.0.json");
	File image = toFile(info.get("img").toString());
	
	SignalServiceDataMessage.Builder message = SignalServiceDataMessage.newBuilder()
			.withBody(info.get("title").toString())
			.withAttachment(SignalServiceAttachment.newStreamBuilder()
					.withContentType("image/png")
					.withLength(image.length())
					.withStream(new FileInputStream(image))
					.build());
	Signal.getInstance().sendMessage(sender, group, message);
	image.delete();
}
 
Example #15
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forVerified(VerifiedMessage verifiedMessage) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.of(verifiedMessage),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #16
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forViewOnceOpen(ViewOnceOpenMessage timerRead) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.of(timerRead),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #17
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forGroups(SignalServiceAttachment groups) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.of(groups),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #18
Source File: JsonAttachment.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
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 #19
Source File: SignalConsole.java    From signal-bot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void sendMessage(List<String> addresses, SignalServiceDataMessage message) throws IOException {
	String out = String.format(
			"Send message to %s:\n"
			+ "%s",
			String.join(", ", addresses),
			message.getBody().or("no body"));
	if(message.getAttachments().isPresent() && !message.getAttachments().get().isEmpty()) {
		Path attachments = Paths.get("attachments");
		if(!Files.exists(attachments)) {
			Files.createDirectory(attachments);
		}
		message.getAttachments().get().stream()
				.map(SignalServiceAttachment::asStream)
				.map(stream -> {
					Path path = attachments.resolve("bot" + System.currentTimeMillis() + "." 
												+ stream.getContentType().split("/")[1]);
					try {
						Files.copy(stream.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
					} catch (IOException e) {
						System.err.println("Could not save an attachment! " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
						return null;
					}
					return path;
				})
				.filter(p -> p != null)
				.forEach(p -> {
					System.out.println("Saved an attachment to " + p.toString());
				});
	}
	System.out.println(out);
}
 
Example #20
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forRequest(RequestMessage request) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.of(request),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #21
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage empty() {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
      Optional.<ContactsMessage>absent(),
      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #22
Source File: SignalServiceSyncMessage.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forRead(List<ReadMessage> reads) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.of(reads),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent());
}
 
Example #23
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forBlocked(BlockedListMessage blocked) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.of(blocked),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.<List<StickerPackOperationMessage>>absent(),
                                      Optional.<FetchType>absent());
}
 
Example #24
Source File: SignalServiceSyncMessage.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forRequest(RequestMessage request) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.of(request),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent());
}
 
Example #25
Source File: SignalServiceSyncMessage.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forGroups(SignalServiceAttachment groups) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.of(groups),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent());
}
 
Example #26
Source File: SignalServiceSyncMessage.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forStickerPackOperations(List<StickerPackOperationMessage> stickerPackOperations) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<ContactsMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<ViewOnceOpenMessage>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent(),
                                      Optional.of(stickerPackOperations),
                                      Optional.<FetchType>absent());
}
 
Example #27
Source File: PointerAttachment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static List<Attachment> forPointers(Optional<List<SignalServiceAttachment>> pointers) {
  List<Attachment> results = new LinkedList<>();

  if (pointers.isPresent()) {
    for (SignalServiceAttachment pointer : pointers.get()) {
      Optional<Attachment> result = forPointer(Optional.of(pointer));

      if (result.isPresent()) {
        results.add(result.get());
      }
    }
  }

  return results;
}
 
Example #28
Source File: SignalServiceSyncMessage.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public static SignalServiceSyncMessage forContacts(ContactsMessage contacts) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.of(contacts),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<BlockedListMessage>absent(),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent(),
                                      Optional.<VerifiedMessage>absent(),
                                      Optional.<ConfigurationMessage>absent());
}
 
Example #29
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
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 #30
Source File: PointerAttachment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static Optional<Attachment> forPointer(Optional<SignalServiceAttachment> pointer, @Nullable StickerLocator stickerLocator, @Nullable String fastPreflightId) {
  if (!pointer.isPresent() || !pointer.get().isPointer()) return Optional.absent();

  String encodedKey = null;

  if (pointer.get().asPointer().getKey() != null) {
    encodedKey = Base64.encodeBytes(pointer.get().asPointer().getKey());
  }

  return Optional.of(new PointerAttachment(pointer.get().getContentType(),
                                    AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
                                    pointer.get().asPointer().getSize().or(0),
                                    pointer.get().asPointer().getFileName().orNull(),
                                    pointer.get().asPointer().getCdnNumber(),
                                    pointer.get().asPointer().getRemoteId().toString(),
                                    encodedKey, null,
                                    pointer.get().asPointer().getDigest().orNull(),
                                    fastPreflightId,
                                    pointer.get().asPointer().getVoiceNote(),
                                    pointer.get().asPointer().getWidth(),
                                    pointer.get().asPointer().getHeight(),
                                    pointer.get().asPointer().getUploadTimestamp(),
                                    pointer.get().asPointer().getCaption().orNull(),
                                    stickerLocator,
                                    BlurHash.parseOrNull(pointer.get().asPointer().getBlurHash().orNull())));

}