Java Code Examples for org.whispersystems.libsignal.util.guava.Optional#orNull()

The following examples show how to use org.whispersystems.libsignal.util.guava.Optional#orNull() . These examples are extracted from open source projects. 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
public IncomingTextMessage(@NonNull RecipientId sender,
                           int senderDeviceId,
                           long sentTimestampMillis,
                           long serverTimestampMillis,
                           String encodedBody,
                           Optional<GroupId> groupId,
                           long expiresInMillis,
                           boolean unidentified)
{
  this.message               = encodedBody;
  this.sender                = sender;
  this.senderDeviceId        = senderDeviceId;
  this.protocol              = 31337;
  this.serviceCenterAddress  = "GCM";
  this.replyPathPresent      = true;
  this.pseudoSubject         = "";
  this.sentTimestampMillis   = sentTimestampMillis;
  this.serverTimestampMillis = serverTimestampMillis;
  this.push                  = true;
  this.subscriptionId        =    -1;
  this.expiresInMillis       = expiresInMillis;
  this.unidentified          = unidentified;
  this.groupId               = groupId.orNull();
}
 
Example 2
public IncomingMediaMessage(Address from,
                            Optional<Address> groupId,
                            String body,
                            long sentTimeMillis,
                            List<Attachment> attachments,
                            int subscriptionId,
                            long expiresIn,
                            boolean expirationUpdate)
{
  this.from             = from;
  this.groupId          = groupId.orNull();
  this.sentTimeMillis   = sentTimeMillis;
  this.body             = body;
  this.push             = false;
  this.subscriptionId   = subscriptionId;
  this.expiresIn        = expiresIn;
  this.expirationUpdate = expirationUpdate;

  this.attachments.addAll(attachments);
}
 
Example 3
public IncomingMediaMessage(MasterSecretUnion masterSecret,
                            Address from,
                            long sentTimeMillis,
                            int subscriptionId,
                            long expiresIn,
                            boolean expirationUpdate,
                            Optional<String> relay,
                            Optional<String> body,
                            Optional<SignalServiceGroup> group,
                            Optional<List<SignalServiceAttachment>> attachments)
{
  this.push             = true;
  this.from             = from;
  this.sentTimeMillis   = sentTimeMillis;
  this.body             = body.orNull();
  this.subscriptionId   = subscriptionId;
  this.expiresIn        = expiresIn;
  this.expirationUpdate = expirationUpdate;
  this.groupId = null;

  this.attachments.addAll(PointerAttachment.forPointers(masterSecret, attachments));
}
 
Example 4
public IncomingMediaMessage(@NonNull RecipientId from,
                            Optional<GroupId> groupId,
                            String body,
                            long sentTimeMillis,
                            long serverTimeMillis,
                            List<Attachment> attachments,
                            int subscriptionId,
                            long expiresIn,
                            boolean expirationUpdate,
                            boolean viewOnce,
                            boolean unidentified)
{
  this.from             = from;
  this.groupId          = groupId.orNull();
  this.sentTimeMillis   = sentTimeMillis;
  this.serverTimeMillis = serverTimeMillis;
  this.body             = body;
  this.push             = false;
  this.subscriptionId   = subscriptionId;
  this.expiresIn        = expiresIn;
  this.expirationUpdate = expirationUpdate;
  this.viewOnce         = viewOnce;
  this.quote            = null;
  this.unidentified     = unidentified;

  this.attachments.addAll(attachments);
}
 
Example 5
public IncomingMediaMessage(@NonNull RecipientId from,
                            long sentTimeMillis,
                            long serverTimeMillis,
                            int subscriptionId,
                            long expiresIn,
                            boolean expirationUpdate,
                            boolean viewOnce,
                            boolean unidentified,
                            Optional<String> body,
                            Optional<SignalServiceGroupContext> group,
                            Optional<List<SignalServiceAttachment>> attachments,
                            Optional<QuoteModel> quote,
                            Optional<List<Contact>> sharedContacts,
                            Optional<List<LinkPreview>> linkPreviews,
                            Optional<Attachment> sticker)
{
  this.push             = true;
  this.from             = from;
  this.sentTimeMillis   = sentTimeMillis;
  this.serverTimeMillis = serverTimeMillis;
  this.body             = body.orNull();
  this.subscriptionId   = subscriptionId;
  this.expiresIn        = expiresIn;
  this.expirationUpdate = expirationUpdate;
  this.viewOnce         = viewOnce;
  this.quote            = quote.orNull();
  this.unidentified     = unidentified;

  if (group.isPresent()) this.groupId = GroupUtil.idFromGroupContextOrThrow(group.get());
  else                   this.groupId = null;

  this.attachments.addAll(PointerAttachment.forPointers(attachments));
  this.sharedContacts.addAll(sharedContacts.or(Collections.emptyList()));
  this.linkPreviews.addAll(linkPreviews.or(Collections.emptyList()));

  if (sticker.isPresent()) {
    this.attachments.add(sticker.get());
  }
}
 
Example 6
@Override
protected Pair<Recipients, RecipientsPreferences> doInBackground(Recipients... recipients) {
  if (recipients.length != 1 || recipients[0] == null) {
    throw new AssertionError("task needs exactly one Recipients object");
  }

  Optional<RecipientsPreferences> prefs = DatabaseFactory.getRecipientPreferenceDatabase(ConversationActivity.this)
                                                         .getRecipientsPreferences(recipients[0].getIds());
  return new Pair<>(recipients[0], prefs.orNull());
}
 
Example 7
private long handleSynchronizeSentMediaMessage(@NonNull SentTranscriptMessage message)
    throws MmsException, BadGroupIdException
{
  MmsDatabase                 database        = DatabaseFactory.getMmsDatabase(context);
  Recipient                   recipients      = getSyncMessageDestination(message);
  Optional<QuoteModel>        quote           = getValidatedQuote(message.getMessage().getQuote());
  Optional<Attachment>        sticker         = getStickerAttachment(message.getMessage().getSticker());
  Optional<List<Contact>>     sharedContacts  = getContacts(message.getMessage().getSharedContacts());
  Optional<List<LinkPreview>> previews        = getLinkPreviews(message.getMessage().getPreviews(), message.getMessage().getBody().or(""));
  boolean                     viewOnce        = message.getMessage().isViewOnce();
  List<Attachment>            syncAttachments = viewOnce ? Collections.singletonList(new TombstoneAttachment(MediaUtil.VIEW_ONCE, false))
                                                         : PointerAttachment.forPointers(message.getMessage().getAttachments());

  if (sticker.isPresent()) {
    syncAttachments.add(sticker.get());
  }

  OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(),
                                                               syncAttachments,
                                                               message.getTimestamp(), -1,
                                                               message.getMessage().getExpiresInSeconds() * 1000,
                                                               viewOnce,
                                                               ThreadDatabase.DistributionTypes.DEFAULT, quote.orNull(),
                                                               sharedContacts.or(Collections.emptyList()),
                                                               previews.or(Collections.emptyList()),
                                                               Collections.emptyList(), Collections.emptyList());

  mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);

  if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
    handleSynchronizeSentExpirationUpdate(message);
  }

  long threadId  = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);

  database.beginTransaction();

  try {
    long messageId = database.insertMessageOutbox(mediaMessage, threadId, false, GroupReceiptDatabase.STATUS_UNKNOWN, null);

    if (recipients.isGroup()) {
      updateGroupReceiptStatus(message, messageId, recipients.requireGroupId());
    } else {
      database.markUnidentified(messageId, isUnidentified(message, recipients));
    }

    database.markAsSent(messageId, true);

    List<DatabaseAttachment> allAttachments     = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageId);
    List<DatabaseAttachment> stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList();
    List<DatabaseAttachment> attachments        = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList();

    forceStickerDownloadIfNecessary(stickerAttachments);

    for (DatabaseAttachment attachment : attachments) {
      ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(messageId, attachment.getAttachmentId(), false));
    }

    if (message.getMessage().getExpiresInSeconds() > 0) {
      database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
      ApplicationContext.getInstance(context)
                        .getExpiringMessageManager()
                        .scheduleDeletion(messageId, true,
                                          message.getExpirationStartTimestamp(),
                                          message.getMessage().getExpiresInSeconds() * 1000L);
    }

    if (recipients.isLocalNumber()) {
      SyncMessageId id = new SyncMessageId(recipients.getId(), message.getTimestamp());
      DatabaseFactory.getMmsSmsDatabase(context).incrementDeliveryReceiptCount(id, System.currentTimeMillis());
      DatabaseFactory.getMmsSmsDatabase(context).incrementReadReceiptCount(id, System.currentTimeMillis());
    }

    database.setTransactionSuccessful();
  } finally {
    database.endTransaction();
  }
  return threadId;
}