org.whispersystems.signalservice.api.messages.SignalServiceGroupContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
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;
}
}