Implement additional message request improvements.

This commit is contained in:
Greyson Parrelli
2020-02-21 13:52:27 -05:00
parent 81c7887d47
commit 1faf196f82
43 changed files with 1523 additions and 361 deletions

View File

@@ -35,6 +35,7 @@ import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
@@ -302,6 +303,8 @@ public class SignalServiceMessageSender {
content = createMultiDeviceStickerPackOperationContent(message.getStickerPackOperations().get());
} else if (message.getFetchType().isPresent()) {
content = createMultiDeviceFetchTypeContent(message.getFetchType().get());
} else if (message.getMessageRequestResponse().isPresent()) {
content = createMultiDeviceMessageRequestResponseContent(message.getMessageRequestResponse().get());
} else if (message.getVerified().isPresent()) {
sendMessage(message.getVerified().get(), unidentifiedAccess);
return;
@@ -818,6 +821,48 @@ public class SignalServiceMessageSender {
return container.setSyncMessage(syncMessage.setFetchLatest(fetchMessage)).build().toByteArray();
}
private byte[] createMultiDeviceMessageRequestResponseContent(MessageRequestResponseMessage message) {
Content.Builder container = Content.newBuilder();
SyncMessage.Builder syncMessage = createSyncMessageBuilder();
SyncMessage.MessageRequestResponse.Builder responseMessage = SyncMessage.MessageRequestResponse.newBuilder();
if (message.getGroupId().isPresent()) {
responseMessage.setGroupId(ByteString.copyFrom(message.getGroupId().get()));
}
if (message.getPerson().isPresent()) {
if (message.getPerson().get().getNumber().isPresent()) {
responseMessage.setThreadE164(message.getPerson().get().getNumber().get());
}
if (message.getPerson().get().getUuid().isPresent()) {
responseMessage.setThreadUuid(message.getPerson().get().getUuid().get().toString());
}
}
switch (message.getType()) {
case ACCEPT:
responseMessage.setType(SyncMessage.MessageRequestResponse.Type.ACCEPT);
break;
case DELETE:
responseMessage.setType(SyncMessage.MessageRequestResponse.Type.DELETE);
break;
case BLOCK:
responseMessage.setType(SyncMessage.MessageRequestResponse.Type.BLOCK);
break;
case BLOCK_AND_DELETE:
responseMessage.setType(SyncMessage.MessageRequestResponse.Type.BLOCK_AND_DELETE);
break;
default:
Log.w(TAG, "Unknown type!");
responseMessage.setType(SyncMessage.MessageRequestResponse.Type.UNKNOWN);
break;
}
syncMessage.setMessageRequestResponse(responseMessage);
return container.setSyncMessage(syncMessage).build().toByteArray();
}
private byte[] createMultiDeviceVerifiedContent(VerifiedMessage verifiedMessage, byte[] nullMessage) {
Content.Builder container = Content.newBuilder();
SyncMessage.Builder syncMessage = createSyncMessageBuilder();

View File

@@ -24,6 +24,7 @@ import org.whispersystems.signalservice.api.messages.calls.OfferMessage;
import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage;
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
@@ -454,6 +455,44 @@ public final class SignalServiceContent {
}
}
if (content.hasMessageRequestResponse()) {
MessageRequestResponseMessage.Type type;
switch (content.getMessageRequestResponse().getType()) {
case ACCEPT:
type = MessageRequestResponseMessage.Type.ACCEPT;
break;
case DELETE:
type = MessageRequestResponseMessage.Type.DELETE;
break;
case BLOCK:
type = MessageRequestResponseMessage.Type.BLOCK;
break;
case BLOCK_AND_DELETE:
type = MessageRequestResponseMessage.Type.BLOCK_AND_DELETE;
break;
default:
type = MessageRequestResponseMessage.Type.UNKNOWN;
break;
}
MessageRequestResponseMessage responseMessage;
if (content.getMessageRequestResponse().hasGroupId()) {
responseMessage = MessageRequestResponseMessage.forGroup(content.getMessageRequestResponse().getGroupId().toByteArray(), type);
} else {
Optional<SignalServiceAddress> address = SignalServiceAddress.fromRaw(content.getMessageRequestResponse().getThreadUuid(), content.getMessageRequestResponse().getThreadE164());
if (address.isPresent()) {
responseMessage = MessageRequestResponseMessage.forIndividual(address.get(), type);
} else {
throw new ProtocolInvalidMessageException(new InvalidMessageException("Message request response has an invalid thread identifier!"), null, 0);
}
}
return SignalServiceSyncMessage.forMessageRequestResponse(responseMessage);
}
return SignalServiceSyncMessage.empty();
}

View File

@@ -0,0 +1,45 @@
package org.whispersystems.signalservice.api.messages.multidevice;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
public class MessageRequestResponseMessage {
private final Optional<SignalServiceAddress> person;
private final Optional<byte[]> groupId;
private final Type type;
public static MessageRequestResponseMessage forIndividual(SignalServiceAddress address, Type type) {
return new MessageRequestResponseMessage(Optional.of(address), Optional.<byte[]>absent(), type);
}
public static MessageRequestResponseMessage forGroup(byte[] groupId, Type type) {
return new MessageRequestResponseMessage(Optional.<SignalServiceAddress>absent(), Optional.of(groupId), type);
}
private MessageRequestResponseMessage(Optional<SignalServiceAddress> person,
Optional<byte[]> groupId,
Type type)
{
this.person = person;
this.groupId = groupId;
this.type = type;
}
public Optional<SignalServiceAddress> getPerson() {
return person;
}
public Optional<byte[]> getGroupId() {
return groupId;
}
public Type getType() {
return type;
}
public enum Type {
UNKNOWN, ACCEPT, DELETE, BLOCK, BLOCK_AND_DELETE, UNBLOCK_AND_ACCEPT
}
}

View File

@@ -26,6 +26,7 @@ public class SignalServiceSyncMessage {
private final Optional<List<StickerPackOperationMessage>> stickerPackOperations;
private final Optional<FetchType> fetchType;
private final Optional<KeysMessage> keys;
private final Optional<MessageRequestResponseMessage> messageRequestResponse;
private SignalServiceSyncMessage(Optional<SentTranscriptMessage> sent,
Optional<ContactsMessage> contacts,
@@ -38,20 +39,22 @@ public class SignalServiceSyncMessage {
Optional<ConfigurationMessage> configuration,
Optional<List<StickerPackOperationMessage>> stickerPackOperations,
Optional<FetchType> fetchType,
Optional<KeysMessage> keys)
Optional<KeysMessage> keys,
Optional<MessageRequestResponseMessage> messageRequestResponse)
{
this.sent = sent;
this.contacts = contacts;
this.groups = groups;
this.blockedList = blockedList;
this.request = request;
this.reads = reads;
this.viewOnceOpen = viewOnceOpen;
this.verified = verified;
this.configuration = configuration;
this.stickerPackOperations = stickerPackOperations;
this.fetchType = fetchType;
this.keys = keys;
this.sent = sent;
this.contacts = contacts;
this.groups = groups;
this.blockedList = blockedList;
this.request = request;
this.reads = reads;
this.viewOnceOpen = viewOnceOpen;
this.verified = verified;
this.configuration = configuration;
this.stickerPackOperations = stickerPackOperations;
this.fetchType = fetchType;
this.keys = keys;
this.messageRequestResponse = messageRequestResponse;
}
public static SignalServiceSyncMessage forSentTranscript(SentTranscriptMessage sent) {
@@ -66,7 +69,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forContacts(ContactsMessage contacts) {
@@ -81,7 +85,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forGroups(SignalServiceAttachment groups) {
@@ -96,7 +101,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forRequest(RequestMessage request) {
@@ -111,7 +117,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forRead(List<ReadMessage> reads) {
@@ -126,7 +133,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forViewOnceOpen(ViewOnceOpenMessage timerRead) {
@@ -141,7 +149,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forRead(ReadMessage read) {
@@ -159,7 +168,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forVerified(VerifiedMessage verifiedMessage) {
@@ -174,7 +184,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forBlocked(BlockedListMessage blocked) {
@@ -189,7 +200,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forConfiguration(ConfigurationMessage configuration) {
@@ -204,7 +216,8 @@ public class SignalServiceSyncMessage {
Optional.of(configuration),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forStickerPackOperations(List<StickerPackOperationMessage> stickerPackOperations) {
@@ -219,7 +232,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.of(stickerPackOperations),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forFetchLatest(FetchType fetchType) {
@@ -234,7 +248,8 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.of(fetchType),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forKeys(KeysMessage keys) {
@@ -249,7 +264,24 @@ public class SignalServiceSyncMessage {
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.of(keys));
Optional.of(keys),
Optional.<MessageRequestResponseMessage>absent());
}
public static SignalServiceSyncMessage forMessageRequestResponse(MessageRequestResponseMessage messageRequestResponse) {
return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
Optional.<ContactsMessage>absent(),
Optional.<SignalServiceAttachment>absent(),
Optional.<BlockedListMessage>absent(),
Optional.<RequestMessage>absent(),
Optional.<List<ReadMessage>>absent(),
Optional.<ViewOnceOpenMessage>absent(),
Optional.<VerifiedMessage>absent(),
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent(),
Optional.of(messageRequestResponse));
}
public static SignalServiceSyncMessage empty() {
@@ -257,14 +289,15 @@ public class SignalServiceSyncMessage {
Optional.<ContactsMessage>absent(),
Optional.<SignalServiceAttachment>absent(),
Optional.<BlockedListMessage>absent(),
Optional.<RequestMessage>absent(),
Optional.<RequestMessage>absent(),
Optional.<List<ReadMessage>>absent(),
Optional.<ViewOnceOpenMessage>absent(),
Optional.<VerifiedMessage>absent(),
Optional.<ConfigurationMessage>absent(),
Optional.<List<StickerPackOperationMessage>>absent(),
Optional.<FetchType>absent(),
Optional.<KeysMessage>absent());
Optional.<KeysMessage>absent(),
Optional.<MessageRequestResponseMessage>absent());
}
public Optional<SentTranscriptMessage> getSent() {
@@ -315,6 +348,10 @@ public class SignalServiceSyncMessage {
return keys;
}
public Optional<MessageRequestResponseMessage> getMessageRequestResponse() {
return messageRequestResponse;
}
public enum FetchType {
LOCAL_PROFILE,
STORAGE_MANIFEST

View File

@@ -340,19 +340,35 @@ message SyncMessage {
optional bytes storageService = 1;
}
optional Sent sent = 1;
optional Contacts contacts = 2;
optional Groups groups = 3;
optional Request request = 4;
repeated Read read = 5;
optional Blocked blocked = 6;
optional Verified verified = 7;
optional Configuration configuration = 9;
optional bytes padding = 8;
repeated StickerPackOperation stickerPackOperation = 10;
optional ViewOnceOpen viewOnceOpen = 11;
optional FetchLatest fetchLatest = 12;
optional Keys keys = 13;
message MessageRequestResponse {
enum Type {
UNKNOWN = 0;
ACCEPT = 1;
DELETE = 2;
BLOCK = 3;
BLOCK_AND_DELETE = 4;
}
optional string threadE164 = 1;
optional string threadUuid = 2;
optional bytes groupId = 3;
optional Type type = 4;
}
optional Sent sent = 1;
optional Contacts contacts = 2;
optional Groups groups = 3;
optional Request request = 4;
repeated Read read = 5;
optional Blocked blocked = 6;
optional Verified verified = 7;
optional Configuration configuration = 9;
optional bytes padding = 8;
repeated StickerPackOperation stickerPackOperation = 10;
optional ViewOnceOpen viewOnceOpen = 11;
optional FetchLatest fetchLatest = 12;
optional Keys keys = 13;
optional MessageRequestResponse messageRequestResponse = 14;
}
message AttachmentPointer {