Add a method to build an OutgoingMessageEntity from an Envelope

This commit is contained in:
Jon Chambers
2022-07-27 16:32:41 -04:00
committed by Jon Chambers
parent d385838dc1
commit 3e0919106d
2 changed files with 68 additions and 3 deletions

View File

@@ -7,13 +7,14 @@ package org.whispersystems.textsecuregcm.entities;
import com.google.protobuf.ByteString;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
public record OutgoingMessageEntity(UUID guid, int type, long timestamp, String source, UUID sourceUuid,
int sourceDevice, UUID destinationUuid, UUID updatedPni, byte[] content,
long serverTimestamp) {
public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullable String source,
@Nullable UUID sourceUuid, int sourceDevice, UUID destinationUuid,
@Nullable UUID updatedPni, byte[] content, long serverTimestamp) {
public MessageProtos.Envelope toEnvelope() {
final MessageProtos.Envelope.Builder builder = MessageProtos.Envelope.newBuilder()
@@ -43,6 +44,20 @@ public record OutgoingMessageEntity(UUID guid, int type, long timestamp, String
return builder.build();
}
public static OutgoingMessageEntity fromEnvelope(final MessageProtos.Envelope envelope) {
return new OutgoingMessageEntity(
UUID.fromString(envelope.getServerGuid()),
envelope.getType().getNumber(),
envelope.getTimestamp(),
envelope.getSource(),
envelope.hasSourceUuid() ? UUID.fromString(envelope.getSourceUuid()) : null,
envelope.getSourceDevice(),
envelope.hasDestinationUuid() ? UUID.fromString(envelope.getDestinationUuid()) : null,
envelope.hasUpdatedPni() ? UUID.fromString(envelope.getUpdatedPni()) : null,
envelope.getContent().toByteArray(),
envelope.getServerTimestamp());
}
@Override
public boolean equals(final Object o) {
if (this == o) {