Add a method to build an OutgoingMessageEntity from an Envelope

This commit is contained in:
Jon Chambers authored and Jon Chambers committed 2022-07-29 10:59:02 -04:00
1 parent d385838dc1
commit 3e0919106d
2 files changed
+68 -3

No files matched your search

@@ -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) {