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

The following examples show how to use org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage. 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
Source Project: mollyim-android   Author: mollyim   File: SendReadReceiptJob.java    License: 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 Project: mollyim-android   Author: mollyim   File: PushProcessMessageJob.java    License: 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 Project: mollyim-android   Author: mollyim   File: SignalServiceMessageSender.java    License: 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 Project: mollyim-android   Author: mollyim   File: SignalServiceMessageSender.java    License: 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 Project: mollyim-android   Author: mollyim   File: SendDeliveryReceiptJob.java    License: 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 Project: mollyim-android   Author: mollyim   File: PushProcessMessageJob.java    License: 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 Project: bcm-android   Author: bcmapp   File: SignalServiceCipher.java    License: 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 Project: bcm-android   Author: bcmapp   File: PushDecryptJob.java    License: 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 Project: bcm-android   Author: bcmapp   File: PushDecryptJob.java    License: 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 Project: bcm-android   Author: bcmapp   File: SendReadReceiptJob.java    License: 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 Project: libsignal-service-java   Author: signalapp   File: SignalServiceMessageSender.java    License: 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 Project: libsignal-service-java   Author: signalapp   File: SignalServiceMessageSender.java    License: 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 Project: libsignal-service-java   Author: signalapp   File: SignalServiceCipher.java    License: 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 Project: signal-cli   Author: AsamK   File: Manager.java    License: 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 Project: signal-cli   Author: AsamK   File: JsonReceiptMessage.java    License: 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 Project: signald   Author: thefinn93   File: JsonReceiptMessage.java    License: 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();
}