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

org.whispersystems.signalservice.api.messages.SignalServiceGroupContext Maven / Gradle / Ivy

There is a newer version: 2.15.3_unofficial_107
Show newest version
package org.whispersystems.signalservice.api.messages;

import org.signal.libsignal.protocol.InvalidMessageException;

import java.util.Optional;


public final class SignalServiceGroupContext {

  private final Optional   groupV1;
  private final Optional groupV2;

  private SignalServiceGroupContext(SignalServiceGroup groupV1) {
    this.groupV1 = Optional.of(groupV1);
    this.groupV2 = Optional.empty();
  }

  private SignalServiceGroupContext(SignalServiceGroupV2 groupV2) {
    this.groupV1 = Optional.empty();
    this.groupV2 = Optional.of(groupV2);
  }

  public Optional getGroupV1() {
    return groupV1;
  }

  public Optional getGroupV2() {
    return groupV2;
  }

  static Optional createOptional(SignalServiceGroup groupV1, SignalServiceGroupV2 groupV2)
      throws InvalidMessageException
  {
    return Optional.ofNullable(create(groupV1, groupV2));
  }

  public static SignalServiceGroupContext create(SignalServiceGroup groupV1, SignalServiceGroupV2 groupV2)
      throws InvalidMessageException
  {
    if (groupV1 == null && groupV2 == null) {
      return null;
    }

    if (groupV1 != null && groupV2 != null) {
      throw new InvalidMessageException("Message cannot have both V1 and V2 group contexts.");
    }

    if (groupV1 != null) {
      return new SignalServiceGroupContext(groupV1);
    } else {
      return new SignalServiceGroupContext(groupV2);
    }
  }

  public SignalServiceGroup.Type getGroupV1Type() {
    if (groupV1.isPresent()) {
      return groupV1.get().getType();
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy