private byte[] createMultiDeviceSentTranscriptContent(byte[] content, May <TextSecureAddress> recipient, ulong timestamp) { try { Content.Builder container = Content.CreateBuilder(); SyncMessage.Builder syncMessage = SyncMessage.CreateBuilder(); SyncMessage.Types.Sent.Builder sentMessage = SyncMessage.Types.Sent.CreateBuilder(); sentMessage.SetTimestamp(timestamp); sentMessage.SetMessage(DataMessage.ParseFrom(content)); if (recipient.HasValue) { sentMessage.SetDestination(recipient.ForceGetValue().getNumber()); } return(container.SetSyncMessage(syncMessage.SetSent(sentMessage)).Build().ToByteArray()); } catch (InvalidProtocolBufferException e) { throw new Exception(e.Message); } }
private TextSecureSyncMessage createSynchronizeMessage(TextSecureEnvelope envelope, SyncMessage content) { if (content.HasSent) { SyncMessage.Types.Sent sentContent = content.Sent; return TextSecureSyncMessage.forSentTranscript(new SentTranscriptMessage(sentContent.Destination, sentContent.Timestamp, createTextSecureMessage(envelope, sentContent.Message))); } if (content.HasRequest) { return TextSecureSyncMessage.forRequest(new RequestMessage(content.Request)); } return TextSecureSyncMessage.empty(); }
public Task<byte[]> Sync(UInt64 ContentId) { Console.WriteLine("attempting to sync " + ContentId); var msg = new SyncMessage() { token = token, content_id = ContentId, dataset_id = (UInt16)DatasetType.CLIPBOARD }; byte[] content = null; var signal = new AutoResetEvent(false); Action<Dictionary<String, Object>> handler = dictionary => { var content_size = Convert.ToUInt32(dictionary["content_size"]); var buffer = new byte[content_size]; if (Recv(buffer, buffer.Length)) content = buffer; signal.Set(); }; lock (rpchandler) rpchandler[(UInt16)MessageType.SYNC_RESPONSE].Enqueue(handler); return Send(serializer.Serialize(msg)) .ContinueWith(task => { if (task.Result) signal.WaitOne(); // block until the next response return content; }); }