private SignalServiceDataMessage CreateSignalServiceMessage(SignalServiceEnvelope envelope, DataMessage content) { SignalServiceGroup groupInfo = CreateGroupInfo(envelope, content); List <SignalServiceAttachment> attachments = new List <SignalServiceAttachment>(); bool endSession = ((content.Flags & (uint)DataMessage.Types.Flags.EndSession) != 0); bool expirationUpdate = ((content.Flags & (uint)DataMessage.Types.Flags.ExpirationTimerUpdate) != 0); bool profileKeyUpdate = ((content.Flags & (uint)DataMessage.Types.Flags.ProfileKeyUpdate) != 0); SignalServiceDataMessage.SignalServiceQuote quote = CreateQuote(envelope, content); foreach (AttachmentPointer pointer in content.Attachments) { attachments.Add(CreateAttachmentPointer(envelope.GetRelay(), pointer)); } if (content.TimestampOneofCase == DataMessage.TimestampOneofOneofCase.Timestamp && (long)content.Timestamp != envelope.GetTimestamp()) { throw new InvalidMessageException("Timestamps don't match: " + content.Timestamp + " vs " + envelope.GetTimestamp()); } return(new SignalServiceDataMessage() { Timestamp = envelope.GetTimestamp(), Group = groupInfo, Attachments = attachments, Body = content.Body, EndSession = endSession, ExpiresInSeconds = (int)content.ExpireTimer, ExpirationUpdate = expirationUpdate, ProfileKey = content.ProfileKeyOneofCase == DataMessage.ProfileKeyOneofOneofCase.ProfileKey ? content.ProfileKey.ToByteArray() : null, ProfileKeyUpdate = profileKeyUpdate, Quote = quote }); }
private SignalServiceGroup CreateGroupInfo(SignalServiceEnvelope envelope, DataMessage content) { if (content.GroupOneofCase == DataMessage.GroupOneofOneofCase.None) { return(null); } SignalServiceGroup.GroupType type; switch (content.Group.Type) { case GroupContext.Types.Type.Deliver: type = SignalServiceGroup.GroupType.DELIVER; break; case GroupContext.Types.Type.Update: type = SignalServiceGroup.GroupType.UPDATE; break; case GroupContext.Types.Type.Quit: type = SignalServiceGroup.GroupType.QUIT; break; case GroupContext.Types.Type.RequestInfo: type = SignalServiceGroup.GroupType.REQUEST_INFO; break; default: type = SignalServiceGroup.GroupType.UNKNOWN; break; } if (content.Group.Type != GroupContext.Types.Type.Deliver) { String name = null; IList <String> members = null; SignalServiceAttachmentPointer avatar = null; if (content.Group.NameOneofCase == GroupContext.NameOneofOneofCase.Name) { name = content.Group.Name; } if (content.Group.Members.Count > 0) { members = content.Group.Members; } if (content.Group.AvatarOneofCase == GroupContext.AvatarOneofOneofCase.Avatar) { AttachmentPointer pointer = content.Group.Avatar; avatar = new SignalServiceAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.GetRelay(), pointer.SizeOneofCase == AttachmentPointer.SizeOneofOneofCase.Size ? pointer.Size : 0, null, 0, 0, pointer.DigestOneofCase == AttachmentPointer.DigestOneofOneofCase.Digest ? pointer.Digest.ToByteArray() : null, null, false); } return(new SignalServiceGroup() { Type = type, GroupId = content.Group.Id.ToByteArray(), Name = name, Members = members, Avatar = avatar }); } return(new SignalServiceGroup() { GroupId = content.Group.Id.ToByteArray(), Type = type }); }
private SignalServiceDataMessage.SignalServiceQuote CreateQuote(SignalServiceEnvelope envelope, DataMessage content) { if (content.QuoteOneofCase != QuoteOneofOneofCase.Quote) { return(null); } List <SignalServiceQuotedAttachment> attachments = new List <SignalServiceQuotedAttachment>(); foreach (var pointer in content.Quote.Attachments) { attachments.Add(new SignalServiceQuotedAttachment(pointer.ContentType, pointer.FileName, pointer.ThumbnailOneofCase == Types.Quote.Types.QuotedAttachment.ThumbnailOneofOneofCase.Thumbnail ? CreateAttachmentPointer(envelope.GetRelay(), pointer.Thumbnail) : null)); } return(new SignalServiceDataMessage.SignalServiceQuote((long)content.Quote.Id, new SignalServiceAddress(content.Quote.Author), content.Quote.Text, attachments)); }
private SignalServiceSyncMessage CreateSynchronizeMessage(SignalServiceEnvelope envelope, SyncMessage content) { if (content.SentOneofCase == SyncMessage.SentOneofOneofCase.Sent) { SyncMessage.Types.Sent sentContent = content.Sent; return(SignalServiceSyncMessage.ForSentTranscript(new SentTranscriptMessage(sentContent.Destination, (long)sentContent.Timestamp, CreateSignalServiceMessage(envelope, sentContent.Message), (long)sentContent.ExpirationStartTimestamp))); } 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(envelope.GetRelay(), pointer), content.Contacts.Complete))); } if (content.GroupsOneofCase == SyncMessage.GroupsOneofOneofCase.Groups) { AttachmentPointer pointer = content.Groups.Blob; return(SignalServiceSyncMessage.ForGroups(CreateAttachmentPointer(envelope.GetRelay(), 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))); } return(SignalServiceSyncMessage.Empty()); }