Java Code Examples for org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#isViewOnce()

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceDataMessage#isViewOnce() . 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
private static boolean isInvalidMessage(@NonNull SignalServiceDataMessage message) {
  if (message.isViewOnce()) {
    List<SignalServiceAttachment> attachments = message.getAttachments().or(Collections.emptyList());

    return attachments.size() != 1  ||
           !isViewOnceSupportedContentType(attachments.get(0).getContentType().toLowerCase());
  }

  return false;
}
 
Example 2
private void handleMediaMessage(@NonNull SignalServiceContent content,
                                @NonNull SignalServiceDataMessage message,
                                @NonNull Optional<Long> smsMessageId)
    throws StorageFailedException, BadGroupIdException
{
  notifyTypingStoppedFromIncomingMessage(getMessageDestination(content, message), content.getSender(), content.getSenderDevice());

  Optional<InsertResult> insertResult;

  MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
  database.beginTransaction();

  try {
    Optional<QuoteModel>        quote          = getValidatedQuote(message.getQuote());
    Optional<List<Contact>>     sharedContacts = getContacts(message.getSharedContacts());
    Optional<List<LinkPreview>> linkPreviews   = getLinkPreviews(message.getPreviews(), message.getBody().or(""));
    Optional<Attachment>        sticker        = getStickerAttachment(message.getSticker());
    IncomingMediaMessage        mediaMessage   = new IncomingMediaMessage(Recipient.externalPush(context, content.getSender()).getId(),
                                                                          message.getTimestamp(),
                                                                          content.getServerTimestamp(),
                                                                          -1,
                                                                          message.getExpiresInSeconds() * 1000L,
                                                                          false,
                                                                          message.isViewOnce(),
                                                                          content.isNeedsReceipt(),
                                                                          message.getBody(),
                                                                          message.getGroupContext(),
                                                                          message.getAttachments(),
                                                                          quote,
                                                                          sharedContacts,
                                                                          linkPreviews,
                                                                          sticker);

    insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);

    if (insertResult.isPresent()) {
      List<DatabaseAttachment> allAttachments     = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
      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(insertResult.get().getMessageId(), attachment.getAttachmentId(), false));
      }

      if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
      }

      database.setTransactionSuccessful();
    }
  } catch (MmsException e) {
    throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice());
  } finally {
    database.endTransaction();
  }

  if (insertResult.isPresent()) {
    ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());

    if (message.isViewOnce()) {
      ApplicationContext.getInstance(context).getViewOnceMessageManager().scheduleIfNecessary();
    }
  }
}