private SignalServiceSyncMessage CreateSynchronizeMessage(Metadata metadata, SyncMessage content) { if (content.SentOneofCase == SyncMessage.SentOneofOneofCase.Sent) { SyncMessage.Types.Sent sentContent = content.Sent; var unidentifiedStatuses = new Dictionary <string, bool>(); foreach (var status in sentContent.UnidentifiedStatus) { unidentifiedStatuses[status.Destination] = status.Unidentified; } return(SignalServiceSyncMessage.ForSentTranscript(new SentTranscriptMessage(sentContent.Destination, (long)sentContent.Timestamp, CreateSignalServiceMessage(metadata, sentContent.Message), (long)sentContent.ExpirationStartTimestamp, unidentifiedStatuses))); } if (content.RequestOneofCase == SyncMessage.RequestOneofOneofCase.Request) { return(SignalServiceSyncMessage.ForRequest(new RequestMessage(content.Request))); } if (content.Read.Count > 0) { List <ReadMessage> readMessages = new List <ReadMessage>(); foreach (SyncMessage.Types.Read read in content.Read) { readMessages.Add(new ReadMessage(read.Sender, (long)read.Timestamp)); } return(SignalServiceSyncMessage.ForRead(readMessages)); } if (content.ContactsOneofCase == SyncMessage.ContactsOneofOneofCase.Contacts) { AttachmentPointer pointer = content.Contacts.Blob; return(SignalServiceSyncMessage.ForContacts(new ContactsMessage(CreateAttachmentPointer(pointer), content.Contacts.Complete))); } if (content.GroupsOneofCase == SyncMessage.GroupsOneofOneofCase.Groups) { AttachmentPointer pointer = content.Groups.Blob; return(SignalServiceSyncMessage.ForGroups(CreateAttachmentPointer(pointer))); } if (content.VerifiedOneofCase == SyncMessage.VerifiedOneofOneofCase.Verified) { try { Verified verified = content.Verified; string destination = verified.Destination; IdentityKey identityKey = new IdentityKey(verified.IdentityKey.ToByteArray(), 0); VerifiedMessage.VerifiedState verifiedState; if (verified.State == Verified.Types.State.Default) { verifiedState = VerifiedMessage.VerifiedState.Default; } else if (verified.State == Verified.Types.State.Verified) { verifiedState = VerifiedMessage.VerifiedState.Verified; } else if (verified.State == Verified.Types.State.Unverified) { verifiedState = VerifiedMessage.VerifiedState.Unverified; } else { throw new InvalidMessageException("Unknown state: " + verified.State); } return(SignalServiceSyncMessage.ForVerified(new VerifiedMessage(destination, identityKey, verifiedState, Util.CurrentTimeMillis()))); } catch (InvalidKeyException e) { throw new InvalidMessageException(e); } } if (content.BlockedOneofCase == SyncMessage.BlockedOneofOneofCase.Blocked) { List <string> blockedNumbers = new List <string>(content.Blocked.Numbers.Count); foreach (var blocked in content.Blocked.Numbers) { blockedNumbers.Add(blocked); } return(SignalServiceSyncMessage.ForBlocked(new BlockedListMessage(blockedNumbers, content.Blocked.GroupIds.Select(gid => gid.ToByteArray()).ToList()))); } if (content.VerifiedOneofCase == SyncMessage.VerifiedOneofOneofCase.Verified) { try { Verified verified = content.Verified; string destination = verified.Destination; IdentityKey identityKey = new IdentityKey(verified.IdentityKey.ToByteArray(), 0); VerifiedMessage.VerifiedState verifiedState; if (verified.State == Verified.Types.State.Default) { verifiedState = VerifiedMessage.VerifiedState.Default; } else if (verified.State == Verified.Types.State.Verified) { verifiedState = VerifiedMessage.VerifiedState.Verified; } else if (verified.State == Verified.Types.State.Unverified) { verifiedState = VerifiedMessage.VerifiedState.Unverified; } else { throw new ProtocolInvalidMessageException(new InvalidMessageException("Unknown state: " + verified.State), metadata.Sender, metadata.SenderDevice); } return(SignalServiceSyncMessage.ForVerified(new VerifiedMessage(destination, identityKey, verifiedState, Util.CurrentTimeMillis()))); } catch (InvalidKeyException e) { throw new ProtocolInvalidKeyException(e, metadata.Sender, metadata.SenderDevice); } } return(SignalServiceSyncMessage.Empty()); }