All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.signal.libsignal.metadata.ProtocolException Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
package org.signal.libsignal.metadata;

import org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent;
import org.whispersystems.libsignal.util.guava.Optional;

public abstract class ProtocolException extends Exception {

  private final Optional content;
  private final String sender;
  private final int senderDevice;

  public ProtocolException(Exception e, String sender, int senderDevice) {
    this.content      = Optional.absent();
    this.sender       = sender;
    this.senderDevice = senderDevice;
  }

  ProtocolException(Exception e, UnidentifiedSenderMessageContent content) {
    this.content      = Optional.of(content);
    this.sender       = content.getSenderCertificate().getSender();
    this.senderDevice = content.getSenderCertificate().getSenderDeviceId();
  }

  public Optional getUnidentifiedSenderMessageContent() {
    return content;
  }

  public String getSender() {
    return sender;
  }

  public int getSenderDevice() {
    return senderDevice;
  }

  public int getContentHint() {
    if (content.isPresent()) {
      return content.get().getContentHint();
    }
    return UnidentifiedSenderMessageContent.CONTENT_HINT_DEFAULT;
  }

  public Optional getGroupId() {
    if (content.isPresent()) {
      return content.get().getGroupId();
    }
    return Optional.absent();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy