mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-15 20:42:00 +00:00
Add pre-alpha receive support for remote delete.
This commit is contained in:
@@ -639,6 +639,13 @@ public class SignalServiceMessageSender {
|
||||
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.REACTIONS_VALUE, builder.getRequiredProtocolVersion()));
|
||||
}
|
||||
|
||||
if (message.getRemoteDelete().isPresent()) {
|
||||
DataMessage.Delete delete = DataMessage.Delete.newBuilder()
|
||||
.setTargetSentTimestamp(message.getRemoteDelete().get().getTargetSentTimestamp())
|
||||
.build();
|
||||
builder.setDelete(delete);
|
||||
}
|
||||
|
||||
builder.setTimestamp(message.getTimestamp());
|
||||
|
||||
return container.setDataMessage(builder).build().toByteArray();
|
||||
|
||||
@@ -293,6 +293,7 @@ public final class SignalServiceContent {
|
||||
List<SignalServiceDataMessage.Preview> previews = createPreviews(content);
|
||||
SignalServiceDataMessage.Sticker sticker = createSticker(content);
|
||||
SignalServiceDataMessage.Reaction reaction = createReaction(content);
|
||||
SignalServiceDataMessage.RemoteDelete remoteDelete = createRemoteDelete(content);
|
||||
|
||||
if (content.getRequiredProtocolVersion() > SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE) {
|
||||
throw new UnsupportedDataMessageProtocolVersionException(SignalServiceProtos.DataMessage.ProtocolVersion.CURRENT_VALUE,
|
||||
@@ -326,7 +327,8 @@ public final class SignalServiceContent {
|
||||
previews,
|
||||
sticker,
|
||||
content.getIsViewOnce(),
|
||||
reaction);
|
||||
reaction,
|
||||
remoteDelete);
|
||||
}
|
||||
|
||||
private static SignalServiceSyncMessage createSynchronizeMessage(SignalServiceMetadata metadata,
|
||||
@@ -660,6 +662,16 @@ public final class SignalServiceContent {
|
||||
reaction.getTargetSentTimestamp());
|
||||
}
|
||||
|
||||
private static SignalServiceDataMessage.RemoteDelete createRemoteDelete(SignalServiceProtos.DataMessage content) {
|
||||
if (!content.hasDelete() || !content.getDelete().hasTargetSentTimestamp()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SignalServiceProtos.DataMessage.Delete delete = content.getDelete();
|
||||
|
||||
return new SignalServiceDataMessage.RemoteDelete(delete.getTargetSentTimestamp());
|
||||
}
|
||||
|
||||
private static List<SharedContact> createSharedContacts(SignalServiceProtos.DataMessage content) throws ProtocolInvalidMessageException {
|
||||
if (content.getContactCount() <= 0) return null;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public class SignalServiceDataMessage {
|
||||
private final Optional<Sticker> sticker;
|
||||
private final boolean viewOnce;
|
||||
private final Optional<Reaction> reaction;
|
||||
private final Optional<RemoteDelete> remoteDelete;
|
||||
|
||||
/**
|
||||
* Construct a SignalServiceDataMessage.
|
||||
@@ -53,7 +54,7 @@ public class SignalServiceDataMessage {
|
||||
String body, boolean endSession, int expiresInSeconds,
|
||||
boolean expirationUpdate, byte[] profileKey, boolean profileKeyUpdate,
|
||||
Quote quote, List<SharedContact> sharedContacts, List<Preview> previews,
|
||||
Sticker sticker, boolean viewOnce, Reaction reaction)
|
||||
Sticker sticker, boolean viewOnce, Reaction reaction, RemoteDelete remoteDelete)
|
||||
{
|
||||
try {
|
||||
this.group = SignalServiceGroupContext.createOptional(group, groupV2);
|
||||
@@ -72,6 +73,7 @@ public class SignalServiceDataMessage {
|
||||
this.sticker = Optional.fromNullable(sticker);
|
||||
this.viewOnce = viewOnce;
|
||||
this.reaction = Optional.fromNullable(reaction);
|
||||
this.remoteDelete = Optional.fromNullable(remoteDelete);
|
||||
|
||||
if (attachments != null && !attachments.isEmpty()) {
|
||||
this.attachments = Optional.of(attachments);
|
||||
@@ -174,6 +176,10 @@ public class SignalServiceDataMessage {
|
||||
return reaction;
|
||||
}
|
||||
|
||||
public Optional<RemoteDelete> getRemoteDelete() {
|
||||
return remoteDelete;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private List<SignalServiceAttachment> attachments = new LinkedList<>();
|
||||
@@ -193,6 +199,7 @@ public class SignalServiceDataMessage {
|
||||
private Sticker sticker;
|
||||
private boolean viewOnce;
|
||||
private Reaction reaction;
|
||||
private RemoteDelete remoteDelete;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
@@ -300,12 +307,17 @@ public class SignalServiceDataMessage {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRemoteDelete(RemoteDelete remoteDelete) {
|
||||
this.remoteDelete = remoteDelete;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SignalServiceDataMessage build() {
|
||||
if (timestamp == 0) timestamp = System.currentTimeMillis();
|
||||
return new SignalServiceDataMessage(timestamp, group, groupV2, attachments, body, endSession,
|
||||
expiresInSeconds, expirationUpdate, profileKey,
|
||||
profileKeyUpdate, quote, sharedContacts, previews,
|
||||
sticker, viewOnce, reaction);
|
||||
sticker, viewOnce, reaction, remoteDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,4 +458,16 @@ public class SignalServiceDataMessage {
|
||||
return targetSentTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RemoteDelete {
|
||||
private final long targetSentTimestamp;
|
||||
|
||||
public RemoteDelete(long targetSentTimestamp) {
|
||||
this.targetSentTimestamp = targetSentTimestamp;
|
||||
}
|
||||
|
||||
public long getTargetSentTimestamp() {
|
||||
return targetSentTimestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,10 @@ message DataMessage {
|
||||
optional uint64 targetSentTimestamp = 5;
|
||||
}
|
||||
|
||||
message Delete {
|
||||
optional uint64 targetSentTimestamp = 1;
|
||||
}
|
||||
|
||||
enum ProtocolVersion {
|
||||
option allow_alias = true;
|
||||
|
||||
@@ -211,6 +215,7 @@ message DataMessage {
|
||||
optional uint32 requiredProtocolVersion = 12;
|
||||
optional bool isViewOnce = 14;
|
||||
optional Reaction reaction = 16;
|
||||
optional Delete delete = 17;
|
||||
}
|
||||
|
||||
message NullMessage {
|
||||
|
||||
Reference in New Issue
Block a user