Java Code Examples for org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage#getTimestamp()

The following examples show how to use org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage#getTimestamp() . 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: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private long handleSynchronizeSentExpirationUpdate(@NonNull SentTranscriptMessage message)
    throws MmsException, BadGroupIdException
{
  MmsDatabase database   = DatabaseFactory.getMmsDatabase(context);
  Recipient   recipient  = getSyncMessageDestination(message);

  OutgoingExpirationUpdateMessage expirationUpdateMessage = new OutgoingExpirationUpdateMessage(recipient,
                                                                                                message.getTimestamp(),
                                                                                                message.getMessage().getExpiresInSeconds() * 1000L);

  long threadId  = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
  long messageId = database.insertMessageOutbox(expirationUpdateMessage, threadId, false, null);

  database.markAsSent(messageId, true);

  DatabaseFactory.getRecipientDatabase(context).setExpireMessages(recipient.getId(), message.getMessage().getExpiresInSeconds());

  return threadId;
}
 
Example 2
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private long handleSynchronizeSentExpirationUpdate(@NonNull MasterSecretUnion masterSecret,
                                                   @NonNull SentTranscriptMessage message) {
    ALog.i(TAG, "handleSynchronizeSentExpirationUpdate");

    PrivateChatRepo chatRepo = repository.getChatRepo();
    Recipient recipient = getSyncMessageDestination(message);

    OutgoingExpirationUpdateMessage expirationUpdateMessage = new OutgoingExpirationUpdateMessage(recipient,
            message.getTimestamp(),
            message.getMessage().getExpiresInSeconds() * 1000);

    long threadId = repository.getThreadRepo().getThreadIdFor(recipient);
    long messageId = chatRepo.insertOutgoingMediaMessage(threadId, masterSecret.getMasterSecret().get(), expirationUpdateMessage, null);

    chatRepo.setMessageSendSuccess(messageId);

    RecipientRepo recipientRepo = Repository.getRecipientRepo(accountContext);
    if (recipientRepo != null) {
        recipientRepo.setExpireTime(recipient, message.getMessage().getExpiresInSeconds());
    }
    return threadId;
}
 
Example 3
Source File: JsonSentTranscriptMessage.java    From signald with GNU General Public License v3.0 5 votes vote down vote up
JsonSentTranscriptMessage(SentTranscriptMessage s, String username) throws IOException, NoSuchAccountException {
    if(s.getDestination().isPresent()) {
        destination = s.getDestination().get();
    }

    timestamp = s.getTimestamp();
    expirationStartTimestamp = s.getExpirationStartTimestamp();
    message = new JsonDataMessage(s.getMessage(), username);
    for(String r : s.getRecipients()) {
        unidentifiedStatus.put(r, s.isUnidentified(r));
    }
    isRecipientUpdate = s.isRecipientUpdate(); 
}
 
Example 4
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 5
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message)
    throws MmsException, BadGroupIdException
{
  Recipient recipient       = getSyncMessageDestination(message);
  String    body            = message.getMessage().getBody().or("");
  long      expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000L;

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

  long    threadId  = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
  boolean isGroup   = recipient.isGroup();

  MessagingDatabase database;
  long              messageId;

  if (isGroup) {
    OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, false, ThreadDatabase.DistributionTypes.DEFAULT, null, Collections.emptyList(), Collections.emptyList());
    outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);

    messageId = DatabaseFactory.getMmsDatabase(context).insertMessageOutbox(outgoingMediaMessage, threadId, false, GroupReceiptDatabase.STATUS_UNKNOWN, null);
    database  = DatabaseFactory.getMmsDatabase(context);

    updateGroupReceiptStatus(message, messageId, recipient.requireGroupId());
  } else {
    OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);

    messageId = DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(threadId, outgoingTextMessage, false, message.getTimestamp(), null);
    database  = DatabaseFactory.getSmsDatabase(context);
    database.markUnidentified(messageId, isUnidentified(message, recipient));
  }

  database.markAsSent(messageId, true);

  if (expiresInMillis > 0) {
    database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
    ApplicationContext.getInstance(context)
                      .getExpiringMessageManager()
                      .scheduleDeletion(messageId, isGroup, message.getExpirationStartTimestamp(), expiresInMillis);
  }

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

  return threadId;
}
 
Example 6
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private long handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret,
                                               @NonNull SentTranscriptMessage message) {
    ALog.i(TAG, "handleSynchronizeSentMediaMessage");

    PrivateChatRepo chatRepo = repository.getChatRepo();
    Recipient recipients = getSyncMessageDestination(message);
    OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(),
            PointerAttachment.forPointers(masterSecret, message.getMessage().getAttachments()),
            message.getTimestamp(), -1,
            message.getMessage().getExpiresInSeconds() * 1000,
            ThreadRepo.DistributionTypes.DEFAULT);

    mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);

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

    long threadId = repository.getThreadRepo().getThreadIdFor(recipients);
    long messageId = chatRepo.insertOutgoingMediaMessage(threadId, masterSecret.getMasterSecret().get(), mediaMessage, null);

    chatRepo.setMessageSendSuccess(messageId);

    for (AttachmentRecord attachment : repository.getAttachmentRepo().getAttachments(messageId)) {
        JobManager jobManager = AmeModuleCenter.INSTANCE.accountJobMgr(accountContext);
        if (jobManager != null) {
            jobManager.add(new AttachmentDownloadJob(context, accountContext, messageId, attachment.getId(), attachment.getUniqueId(), false));
        }
    }

    if (message.getMessage().getExpiresInSeconds() > 0) {
        chatRepo.setMessageExpiresStart(messageId);

        IExpiringScheduler manager = ExpirationManager.INSTANCE.get(accountContext);
        manager.scheduleDeletion(messageId, true,
                message.getExpirationStartTimestamp(),
                message.getMessage().getExpiresInSeconds() * 1000);

    }

    return threadId;
}
 
Example 7
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private long handleSynchronizeSentTextMessage(@NonNull MasterSecretUnion masterSecret,
                                              @NonNull SentTranscriptMessage message) {

    ALog.i(TAG, "handleSynchronizeSentTextMessage");

    Recipient recipient = getSyncMessageDestination(message);
    String body = message.getMessage().getBody().or("");
    long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000;

    if (recipient.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(masterSecret, message);
    }

    long threadId = repository.getThreadRepo().getThreadIdFor(recipient);

    PrivateChatRepo chatRepo = repository.getChatRepo();
    long messageId;

    if (recipient.getAddress().isGroup()) {
        OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, ThreadRepo.DistributionTypes.DEFAULT);
        outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);

        messageId = chatRepo.insertOutgoingMediaMessage(threadId, masterSecret.getMasterSecret().get(), outgoingMediaMessage, null);
    } else {
        OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);

        messageId = chatRepo.insertOutgoingTextMessage(threadId, outgoingTextMessage, message.getTimestamp(), null);
    }

    chatRepo.setMessageSendSuccess(messageId);

    if (expiresInMillis > 0) {
        chatRepo.setMessageExpiresStart(messageId);
        chatRepo.setMessageExpiresStart(messageId);

        IExpiringScheduler manager = ExpirationManager.INSTANCE.get(accountContext);
        manager.scheduleDeletion(messageId, false, message.getExpirationStartTimestamp(), expiresInMillis);
    }

    return threadId;
}