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

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage. 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: SendReadReceiptJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  if (!TextSecurePreferences.isReadReceiptsEnabled(context) || messageIds.isEmpty()) return;

  if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
    Log.w(TAG, "Refusing to send receipts to untrusted recipient");
    return;
  }

  Recipient                   recipient      = Recipient.resolved(recipientId);
  SignalServiceMessageSender  messageSender  = ApplicationDependencies.getSignalServiceMessageSender();
  SignalServiceAddress        remoteAddress  = RecipientUtil.toSignalServiceAddress(context, recipient);
  SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageIds, timestamp);

  messageSender.sendReceipt(remoteAddress,
                            UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)),
                            receiptMessage);
}
 
Example #2
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("DefaultLocale")
private void handleReadReceipt(@NonNull SignalServiceContent content,
                               @NonNull SignalServiceReceiptMessage message)
{
  if (TextSecurePreferences.isReadReceiptsEnabled(context)) {
    for (long timestamp : message.getTimestamps()) {
      Log.i(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp));

      Recipient     sender  = Recipient.externalPush(context, content.getSender());
      SyncMessageId id      = new SyncMessageId(sender.getId(), timestamp);
      boolean       handled = DatabaseFactory.getMmsSmsDatabase(context)
                                             .incrementReadReceiptCount(id, content.getTimestamp());

      if (!handled) {
        Log.w(TAG, "[handleReadReceipt] Could not find matching message! timestamp: " + timestamp + "  author: " + sender.getId());
        ApplicationDependencies.getEarlyMessageCache().store(sender.getId(), timestamp, content);
      }
    }
  }
}
 
Example #3
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a read receipt for a received message.
 *
 * @param recipient The sender of the received message you're acknowledging.
 * @param message The read receipt to deliver.
 * @throws IOException
 * @throws UntrustedIdentityException
 */
public void sendReceipt(SignalServiceAddress recipient,
                        Optional<UnidentifiedAccessPair> unidentifiedAccess,
                        SignalServiceReceiptMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createReceiptContent(message);

  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getWhen(), content, false);
}
 
Example #4
Source File: SignalServiceMessageSender.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createReceiptContent(SignalServiceReceiptMessage message) {
  Content.Builder        container = Content.newBuilder();
  ReceiptMessage.Builder builder   = ReceiptMessage.newBuilder();

  for (long timestamp : message.getTimestamps()) {
    builder.addTimestamp(timestamp);
  }

  if      (message.isDeliveryReceipt()) builder.setType(ReceiptMessage.Type.DELIVERY);
  else if (message.isReadReceipt())     builder.setType(ReceiptMessage.Type.READ);

  return container.setReceiptMessage(builder).build().toByteArray();
}
 
Example #5
Source File: SendDeliveryReceiptJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRun() throws IOException, UntrustedIdentityException {
  SignalServiceMessageSender  messageSender  = ApplicationDependencies.getSignalServiceMessageSender();
  Recipient                   recipient      = Recipient.resolved(recipientId);
  SignalServiceAddress        remoteAddress  = RecipientUtil.toSignalServiceAddress(context, recipient);
  SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
                                                                               Collections.singletonList(messageId),
                                                                               timestamp);

  messageSender.sendReceipt(remoteAddress,
                            UnidentifiedAccessUtil.getAccessFor(context, recipient),
                            receiptMessage);
}
 
Example #6
Source File: PushProcessMessageJob.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("DefaultLocale")
private void handleDeliveryReceipt(@NonNull SignalServiceContent content,
                                   @NonNull SignalServiceReceiptMessage message)
{
  for (long timestamp : message.getTimestamps()) {
    Log.i(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp));
    DatabaseFactory.getMmsSmsDatabase(context)
                   .incrementDeliveryReceiptCount(new SyncMessageId(Recipient.externalPush(context, content.getSender()).getId(), timestamp), System.currentTimeMillis());
  }
}
 
Example #7
Source File: SignalServiceCipher.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceReceiptMessage createReceiptMessage(SignalServiceProtos.Envelope envelope, ReceiptMessage content) {
  SignalServiceReceiptMessage.Type type;

  if      (content.getType() == ReceiptMessage.Type.DELIVERY) type = SignalServiceReceiptMessage.Type.DELIVERY;
  else if (content.getType() == ReceiptMessage.Type.READ)     type = SignalServiceReceiptMessage.Type.READ;
  else                                                        type = SignalServiceReceiptMessage.Type.UNKNOWN;

  return new SignalServiceReceiptMessage(type, content.getTimestampList(), envelope.getTimestamp());
}
 
Example #8
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleDeliveryReceipt(@NonNull SignalServiceProtos.Envelope envelope,
                                   @NonNull SignalServiceReceiptMessage message) {
    ALog.i(TAG, "handleDeliveryReceipt");

    for (long timestamp : message.getTimestamps()) {
        Log.w(TAG, String.format("Received encrypted delivery receipt: (XXXXX, %d)", timestamp));
        repository.getChatRepo().incrementDeliveryReceiptCount(envelope.getSource(), timestamp);
    }
}
 
Example #9
Source File: PushDecryptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void handleReadReceipt(@NonNull SignalServiceProtos.Envelope envelope,
                               @NonNull SignalServiceReceiptMessage message) {
    ALog.i(TAG, "handleReadReceipt");

    if (TextSecurePreferences.isReadReceiptsEnabled(accountContext)) {
        for (long timestamp : message.getTimestamps()) {
            Log.w(TAG, String.format("Received encrypted read receipt: (XXXXX, %d)", timestamp));

            repository.getChatRepo().incrementReadReceiptCount(envelope.getSource(), timestamp);
        }
    }
}
 
Example #10
Source File: SendReadReceiptJob.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRun() throws Exception {
    if (!TextSecurePreferences.isReadReceiptsEnabled(accountContext)) return;

    SignalServiceAddress remoteAddress = new SignalServiceAddress(address);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageIds, timestamp);

    BcmChatCore.INSTANCE.sendReceipt(accountContext, remoteAddress, receiptMessage);
}
 
Example #11
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send a read receipt for a received message.
 *
 * @param recipient The sender of the received message you're acknowledging.
 * @param message The read receipt to deliver.
 * @throws IOException
 * @throws UntrustedIdentityException
 */
public void sendReceipt(SignalServiceAddress recipient,
                        Optional<UnidentifiedAccessPair> unidentifiedAccess,
                        SignalServiceReceiptMessage message)
    throws IOException, UntrustedIdentityException
{
  byte[] content = createReceiptContent(message);

  sendMessage(recipient, getTargetUnidentifiedAccess(unidentifiedAccess), message.getWhen(), content, false);
}
 
Example #12
Source File: SignalServiceMessageSender.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private byte[] createReceiptContent(SignalServiceReceiptMessage message) {
  Content.Builder        container = Content.newBuilder();
  ReceiptMessage.Builder builder   = ReceiptMessage.newBuilder();

  for (long timestamp : message.getTimestamps()) {
    builder.addTimestamp(timestamp);
  }

  if      (message.isDeliveryReceipt()) builder.setType(ReceiptMessage.Type.DELIVERY);
  else if (message.isReadReceipt())     builder.setType(ReceiptMessage.Type.READ);

  return container.setReceiptMessage(builder).build().toByteArray();
}
 
Example #13
Source File: SignalServiceCipher.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
private SignalServiceReceiptMessage createReceiptMessage(Metadata metadata, ReceiptMessage content) {
  SignalServiceReceiptMessage.Type type;

  if      (content.getType() == ReceiptMessage.Type.DELIVERY) type = SignalServiceReceiptMessage.Type.DELIVERY;
  else if (content.getType() == ReceiptMessage.Type.READ)     type = SignalServiceReceiptMessage.Type.READ;
  else                                                        type = SignalServiceReceiptMessage.Type.UNKNOWN;

  return new SignalServiceReceiptMessage(type, content.getTimestampList(), metadata.getTimestamp());
}
 
Example #14
Source File: Manager.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
void sendReceipt(SignalServiceAddress remoteAddress, long messageId) throws IOException, UntrustedIdentityException {
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
            Collections.singletonList(messageId),
            System.currentTimeMillis());

    getMessageSender().sendReceipt(remoteAddress, getAccessFor(remoteAddress), receiptMessage);
}
 
Example #15
Source File: JsonReceiptMessage.java    From signal-cli with GNU General Public License v3.0 5 votes vote down vote up
JsonReceiptMessage(SignalServiceReceiptMessage receiptMessage) {

        this.when = receiptMessage.getWhen();
        if (receiptMessage.isDeliveryReceipt()) {
            this.isDelivery = true;
        }
        if (receiptMessage.isReadReceipt()) {
            this.isRead = true;
        }
        this.timestamps = receiptMessage.getTimestamps();
    }
 
Example #16
Source File: JsonReceiptMessage.java    From signald with GNU General Public License v3.0 4 votes vote down vote up
JsonReceiptMessage(SignalServiceReceiptMessage receiptMessage) {
    type = receiptMessage.getType().name();
    timestamps = receiptMessage.getTimestamps();
    when = receiptMessage.getWhen();
}