public void handle(SignalServiceEnvelope envelope, bool sendExplicitReceipt) { if (!isActiveNumber(envelope.getSource())) { TextSecureDirectory directory = DatabaseFactory.getDirectoryDatabase(); ContactTokenDetails contactTokenDetails = new ContactTokenDetails(); contactTokenDetails.setNumber(envelope.getSource()); directory.setNumber(contactTokenDetails, true); // TODO: evtl DirectoryRefresh } if (envelope.isReceipt()) { handleReceipt(envelope); } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) { handleMessage(envelope, sendExplicitReceipt); } else { Log.Warn($"Received envelope of unknown type: {envelope.GetType()}"); } }
public static SignalMessage IncreaseReceiptCountLocked(SignalServiceEnvelope envelope) { SignalMessage m; bool set_mark = false; lock (DBLock) { using (var ctx = new SignalDBContext()) { m = ctx.Messages.SingleOrDefault(t => t.ComposedTimestamp == envelope.GetTimestamp()); if (m != null) { m.Receipts++; if (m.Status == SignalMessageStatus.Confirmed) { m.Status = SignalMessageStatus.Received; set_mark = true; } } else { ctx.EarlyReceipts.Add(new SignalEarlyReceipt() { DeviceId = (uint)envelope.GetSourceDevice(), Timestamp = envelope.GetTimestamp(), Username = envelope.GetSourceE164() }); } ctx.SaveChanges(); } } return(set_mark ? m : null); }
private void handleSynchronizeSentMessage(SignalServiceEnvelope envelope, SentTranscriptMessage message, May <long> smsMessageId) // throws MmsException { long threadId; if (message.getMessage().isGroupUpdate()) { throw new NotImplementedException("GROUP handleSynchronizeSentMessage"); //threadId = GroupMessageProcessor.process(context, masterSecret, envelope, message.getMessage(), true); // TODO: Group enable } else if (message.getMessage().getAttachments().HasValue) { threadId = handleSynchronizeSentMediaMessage(message, smsMessageId); } else { threadId = handleSynchronizeSentTextMessage(message, smsMessageId); } if (threadId == 0L) { return; } DatabaseFactory.getThreadDatabase().SetRead(threadId); //MessageNotifier.updateNotification(getContext(), masterSecret.getMasterSecret().orNull()); }
private void handleMediaMessage(SignalServiceEnvelope envelope, SignalServiceDataMessage message, May <long> smsMessageId) // throws MmsException { throw new NotImplementedException("handleMediaMessage"); /* * var database = DatabaseFactory.getMediaMessageDatabase(); //getMmsDatabase(context); * String localNumber = TextSecurePreferences.getLocalNumber(context); * IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), * localNumber, message.getTimestamp(), * Optional.fromNullable(envelope.getRelay()), * message.getBody(), * message.getGroupInfo(), * message.getAttachments()); * * Pair<long, long> messageAndThreadId = database.insertSecureDecryptedMessageInbox(mediaMessage, -1); * List<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageAndThreadId.first); * * for (DatabaseAttachment attachment : attachments) * { * ApplicationContext.getInstance(context) * .getJobManager() * .add(new AttachmentDownloadJob(context, messageAndThreadId.first, * attachment.getAttachmentId())); * } * * if (smsMessageId.isPresent()) * { * DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get()); * } * * MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second);*/ }
private byte[] decrypt(SignalServiceEnvelope envelope, byte[] ciphertext) { SignalProtocolAddress sourceAddress = new SignalProtocolAddress(envelope.getSource(), (uint)envelope.getSourceDevice()); SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, sourceAddress); byte[] paddedMessage; if (envelope.isPreKeySignalMessage()) { paddedMessage = sessionCipher.decrypt(new PreKeySignalMessage(ciphertext)); } else if (envelope.isSignalMessage()) { paddedMessage = sessionCipher.decrypt(new SignalMessage(ciphertext)); } else { throw new InvalidMessageException("Unknown type: " + envelope.getType() + " from " + envelope.getSource()); } PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion()); return(transportDetails.getStrippedPaddingMessageBody(paddedMessage)); }
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 }); }
/// <summary> /// Decrypt a received <see cref="SignalServiceEnvelope"/> /// </summary> /// <param name="envelope">The received SignalServiceEnvelope</param> /// <returns>a decrypted SignalServiceContent</returns> public SignalServiceContent decrypt(SignalServiceEnvelope envelope) { try { SignalServiceContent content = new SignalServiceContent(); if (envelope.hasLegacyMessage()) { DataMessage message = DataMessage.ParseFrom(decrypt(envelope, envelope.getLegacyMessage())); content = new SignalServiceContent(createSignalServiceMessage(envelope, message)); } else if (envelope.hasContent()) { Content message = Content.ParseFrom(decrypt(envelope, envelope.getContent())); if (message.HasDataMessage) { content = new SignalServiceContent(createSignalServiceMessage(envelope, message.DataMessage)); } else if (message.HasSyncMessage && localAddress.getNumber().Equals(envelope.getSource())) { content = new SignalServiceContent(createSynchronizeMessage(envelope, message.SyncMessage)); } } return(content); } catch (InvalidProtocolBufferException e) { throw new InvalidMessageException(e); } }
private void handleEndSessionMessage(SignalServiceEnvelope envelope, SignalServiceDataMessage message, May <long> smsMessageId) { var smsDatabase = DatabaseFactory.getTextMessageDatabase();//getEncryptingSmsDatabase(context); var incomingTextMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), "", May <SignalServiceGroup> .NoValue); long threadId; if (!smsMessageId.HasValue) { IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage); Pair <long, long> messageAndThreadId = smsDatabase.InsertMessageInbox(incomingEndSessionMessage); threadId = messageAndThreadId.second(); } else { var messageId = smsMessageId.ForceGetValue(); smsDatabase.MarkAsEndSession(messageId); threadId = smsDatabase.GetThreadIdForMessage(messageId); } SessionStore sessionStore = new TextSecureAxolotlStore(); sessionStore.DeleteAllSessions(envelope.getSource()); //SecurityEvent.broadcastSecurityUpdateEvent(context, threadId); //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId); }
/// <summary> /// Blocks until a message was received, calls the IMessagePipeCallback and confirms the message to the server, unless the pipe's token is cancelled. /// </summary> /// <param name="callback"></param> public async Task ReadBlocking(IMessagePipeCallback callback) { Logger.LogTrace("ReadBlocking()"); WebSocketRequestMessage request = Websocket.ReadRequestBlocking(); if (IsSignalServiceEnvelope(request)) { SignalServiceMessagePipeMessage message = new SignalServiceEnvelope(request.Body.ToByteArray(), CredentialsProvider.SignalingKey); WebSocketResponseMessage response = CreateWebSocketResponse(request); try { Logger.LogDebug("Calling callback with message {0}", request.Id); await callback.OnMessage(message); } finally { if (!Token.IsCancellationRequested) { Logger.LogDebug("Confirming message {0}", request.Id); Websocket.SendResponse(response); } } } else if (IsPipeEmptyMessage(request)) { Logger.LogInformation("Calling callback with SignalServiceMessagePipeEmptyMessage"); await callback.OnMessage(new SignalServiceMessagePipeEmptyMessage()); } else { Logger.LogWarning("Unknown request: {0} {1}", request.Verb, request.Path); } }
public void ReadBlocking(MessagePipeCallback callback) { LinkedList <WebSocketRequestMessage> requests = Websocket.readRequests(); int amount = requests.Count; SignalServiceEnvelope[] envelopes = new SignalServiceEnvelope[amount]; WebSocketResponseMessage[] responses = new WebSocketResponseMessage[amount]; for (int i = 0; i < amount; i++) { WebSocketRequestMessage msg = requests.First.Value; requests.RemoveFirst(); if (isSignalServiceEnvelope(msg)) { envelopes[i] = new SignalServiceEnvelope(msg.Body.ToByteArray(), CredentialsProvider.GetSignalingKey()); } responses[i] = createWebSocketResponse(msg); } try { callback.onMessages(envelopes); } finally { foreach (WebSocketResponseMessage response in responses) { Websocket.SendResponse(response); } } }
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); foreach (AttachmentPointer pointer in content.Attachments) { attachments.Add(new SignalServiceAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.getRelay(), pointer.SizeOneofCase == AttachmentPointer.SizeOneofOneofCase.Size ? pointer.Size : 0, pointer.ThumbnailOneofCase == AttachmentPointer.ThumbnailOneofOneofCase.Thumbnail ? pointer.Thumbnail.ToByteArray() : null, pointer.DigestOneofCase == AttachmentPointer.DigestOneofOneofCase.Digest ? pointer.Digest.ToByteArray() : null, pointer.FileNameOneofCase == AttachmentPointer.FileNameOneofOneofCase.FileName ? pointer.FileName : null, pointer.FlagsOneofCase == AttachmentPointer.FlagsOneofOneofCase.Flags && (pointer.Flags & (uint)AttachmentPointer.Types.Flags.VoiceMessage) != 0)); } return(new SignalServiceDataMessage() { Timestamp = envelope.getTimestamp(), Group = groupInfo, Attachments = attachments, Body = content.Body, EndSession = endSession, ExpiresInSeconds = (int)content.ExpireTimer, ExpirationUpdate = expirationUpdate }); }
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)); } return(SignalServiceSyncMessage.empty()); }
private void processIncomingMessageRecord(MessageRecord record) { try { PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(); var messageDatabase = DatabaseFactory.getMessageDatabase(); messageDatabase.RemoveMismatchedIdentity(record.MessageId, mismatch.RecipientId, mismatch.IdentityKey); SignalServiceEnvelope envelope = new SignalServiceEnvelope((int)SignalServiceProtos.Envelope.Types.Type.PREKEY_BUNDLE, record.IndividualRecipient.getNumber(), (int)record.RecipientDeviceId, "", (long)TimeUtil.GetUnixTimestamp(record.DateSent), Base64.decode(record.Body.Body), null); long pushId = pushDatabase.Insert(envelope); var task = new PushDecryptTask(pushId, record.MessageId, record.IndividualRecipient.getNumber()); App.Current.Worker.AddTaskActivities(task); } catch (IOException e) { throw new Exception(); } }
private void OnMessageRecevied(SignalServiceMessagePipe sender, SignalServiceEnvelope envelope) { Log.Debug("Push message recieved"); var task = new PushContentReceiveTask(); task.handle(envelope, false); //throw new NotImplementedException("OnMessageReceived"); }
private void handleGroupMessage(SignalServiceEnvelope envelope, SignalServiceDataMessage message, May <long> smsMessageId) { //GroupMessageProcessor.process(envelope, message, false); // TODO: GROUP enable if (smsMessageId.HasValue) { DatabaseFactory.getTextMessageDatabase().DeleteThread(smsMessageId.ForceGetValue()); //getSmsDatabase(context).deleteMessage(smsMessageId.get()); } }
private Pair <long, long> insertPlaceholder(SignalServiceEnvelope envelope) { var database = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context); IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), "", May <SignalServiceGroup> .NoValue); textMessage = new IncomingEncryptedMessage(textMessage, ""); return(database.InsertMessageInbox(textMessage)); }
/// <summary> /// Decrypt a received <see cref="SignalServiceEnvelope"/> /// </summary> /// <param name="envelope">The received SignalServiceEnvelope</param> /// <returns>a decrypted SignalServiceContent</returns> public SignalServiceContent Decrypt(SignalServiceEnvelope envelope) { try { SignalServiceContent content = new SignalServiceContent(); if (envelope.HasLegacyMessage()) { DataMessage message = DataMessage.Parser.ParseFrom(Decrypt(envelope, envelope.GetLegacyMessage())); content = new SignalServiceContent() { Message = CreateSignalServiceMessage(envelope, message) }; } else if (envelope.HasContent()) { Content message = Content.Parser.ParseFrom(Decrypt(envelope, envelope.GetContent())); if (message.DataMessageOneofCase == Content.DataMessageOneofOneofCase.DataMessage) { content = new SignalServiceContent() { Message = CreateSignalServiceMessage(envelope, message.DataMessage) }; } else if (message.SyncMessageOneofCase == Content.SyncMessageOneofOneofCase.SyncMessage && LocalAddress.E164number == envelope.GetSource()) { content = new SignalServiceContent() { SynchronizeMessage = CreateSynchronizeMessage(envelope, message.SyncMessage) }; } else if (message.CallMessageOneofCase == Content.CallMessageOneofOneofCase.CallMessage) { content = new SignalServiceContent() { CallMessage = CreateCallMessage(message.CallMessage) }; } else if (message.ReceiptMessageOneofCase == Content.ReceiptMessageOneofOneofCase.ReceiptMessage) { content = new SignalServiceContent() { ReadMessage = CreateReceiptMessage(envelope, message.ReceiptMessage) }; } } return(content); } catch (InvalidProtocolBufferException e) { throw new InvalidMessageException(e); } }
private async Task HandleSessionResetMessage(SignalServiceEnvelope envelope, SignalServiceContent content, SignalServiceDataMessage dataMessage, bool isSync, long timestamp) { SignalMessageDirection type; SignalContact author; SignalMessageStatus status; SignalConversation conversation; string prefix; string conversationId; Guid? conversationGuid; long composedTimestamp; if (isSync) { var sent = content.SynchronizeMessage.Sent; type = SignalMessageDirection.Synced; status = SignalMessageStatus.Confirmed; composedTimestamp = sent.Timestamp; author = null; prefix = "You have"; conversationId = sent.Destination.E164; conversationGuid = sent.Destination.Uuid; } else { status = 0; type = SignalMessageDirection.Incoming; author = await SignalDBContext.GetOrCreateContactLocked(content.Sender.E164, content.Sender.Uuid); prefix = $"{author.ThreadDisplayName} has"; composedTimestamp = envelope.GetTimestamp(); conversationId = content.Sender.E164; conversationGuid = content.Sender.Uuid; } LibsignalDBContext.DeleteAllSessions(conversationId); conversation = await SignalDBContext.GetOrCreateContactLocked(conversationId, conversationGuid); SignalMessage sm = new SignalMessage() { Direction = type, Type = SignalMessageType.SessionReset, Status = status, Author = author, Content = new SignalMessageContent() { Content = $"{prefix} reset the session." }, ThreadId = conversationId, ThreadGuid = conversationGuid, DeviceId = (uint)envelope.GetSourceDevice(), Receipts = 0, ComposedTimestamp = composedTimestamp, ReceivedTimestamp = timestamp, }; await SignalLibHandle.Instance.SaveAndDispatchSignalMessage(sm, null, conversation); }
protected override async Task <string> ExecuteAsync() { PushDatabase database = DatabaseFactory.getPushDatabase(); SignalServiceEnvelope envelope = database.GetEnvelope(_pushMessageId); May <long> optionalSmsMessageId = _smsMessageId > 0 ? new May <long>(_smsMessageId) : May <long> .NoValue; handleMessage(envelope, optionalSmsMessageId); database.Delete(_pushMessageId); return(""); }
private void HandleSessionResetMessage(SignalServiceEnvelope envelope, SignalServiceContent content, SignalServiceDataMessage dataMessage, bool isSync, long timestamp) { SignalMessageDirection type; SignalContact author; SignalMessageStatus status; string prefix; string conversationId; long composedTimestamp; if (isSync) { var sent = content.SynchronizeMessage.getSent().ForceGetValue(); type = SignalMessageDirection.Synced; status = SignalMessageStatus.Confirmed; composedTimestamp = sent.getTimestamp(); author = null; prefix = "You have"; conversationId = sent.getDestination().ForceGetValue(); } else { status = 0; type = SignalMessageDirection.Incoming; author = SignalDBContext.GetOrCreateContactLocked(envelope.getSource(), timestamp, this); prefix = $"{author.ThreadDisplayName} has"; composedTimestamp = envelope.getTimestamp(); conversationId = envelope.getSource(); } LibsignalDBContext.DeleteAllSessions(conversationId); SignalMessage sm = new SignalMessage() { Direction = type, Type = SignalMessageType.SessionReset, Status = status, Author = author, Content = new SignalMessageContent() { Content = $"{prefix} reset the session." }, ThreadId = conversationId, DeviceId = (uint)envelope.getSourceDevice(), Receipts = 0, ComposedTimestamp = composedTimestamp, ReceivedTimestamp = timestamp, }; Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await UIHandleIncomingMessage(sm); }).AsTask().Wait(); }
private void handleDuplicateMessage(SignalServiceEnvelope envelope, May <long> smsMessageId) { // Let's start ignoring these now // SmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context); // // if (smsMessageId <= 0) { // Pair<Long, Long> messageAndThreadId = insertPlaceholder(masterSecret, envelope); // smsDatabase.markAsDecryptDuplicate(messageAndThreadId.first); // MessageNotifier.updateNotification(context, masterSecret, messageAndThreadId.second); // } else { // smsDatabase.markAsDecryptDuplicate(smsMessageId); // } }
private SignalServiceGroup createGroupInfo(SignalServiceEnvelope envelope, DataMessage content) { if (!content.HasGroup) { return(null); } SignalServiceGroup.Type type; switch (content.Group.Type) { case GroupContext.Types.Type.DELIVER: type = SignalServiceGroup.Type.DELIVER; break; case GroupContext.Types.Type.UPDATE: type = SignalServiceGroup.Type.UPDATE; break; case GroupContext.Types.Type.QUIT: type = SignalServiceGroup.Type.QUIT; break; case GroupContext.Types.Type.REQUEST_INFO: type = SignalServiceGroup.Type.REQUEST_INFO; break; default: type = SignalServiceGroup.Type.UNKNOWN; break; } if (content.Group.Type != GroupContext.Types.Type.DELIVER) { String name = null; IList <String> members = null; SignalServiceAttachmentPointer avatar = null; if (content.Group.HasName) { name = content.Group.Name; } if (content.Group.MembersCount > 0) { members = content.Group.MembersList; } if (content.Group.HasAvatar) { avatar = new SignalServiceAttachmentPointer(content.Group.Avatar.Id, content.Group.Avatar.ContentType, content.Group.Avatar.Key.ToByteArray(), envelope.getRelay()); } return(new SignalServiceGroup(type, content.Group.Id.ToByteArray(), name, members, avatar)); } return(new SignalServiceGroup(content.Group.Id.ToByteArray())); }
private void handleMessage(SignalServiceEnvelope envelope, bool sendExplicitReceipt) { var worker = App.Current.Worker; long messageId = DatabaseFactory.getPushDatabase().Insert(envelope); if (sendExplicitReceipt) { worker.AddTaskActivities(new DeliveryReceiptTask(envelope.getSource(), envelope.getTimestamp(), envelope.getRelay())); } worker.AddTaskActivities(new PushDecryptTask(messageId, envelope.getSource())); }
protected override async Task <string> ExecuteAsync() { try { String sessionKey = TextSecurePreferences.getSignalingKey(); SignalServiceEnvelope envelope = new SignalServiceEnvelope(data, sessionKey); handle(envelope, true); } catch (/*IOException | InvalidVersion*/ Exception e) { Debug.WriteLine($"{this.GetType().Name}: Error: {e.Message}"); } return(""); }
private void handleLegacyMessage(SignalServiceEnvelope envelope, May <long> smsMessageId) { var smsDatabase = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context); if (!smsMessageId.HasValue) { Pair <long, long> messageAndThreadId = insertPlaceholder(envelope); smsDatabase.MarkAsLegacyVersion(messageAndThreadId.first()); //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second); } else { smsDatabase.MarkAsLegacyVersion(smsMessageId.ForceGetValue()); } }
public async Task <List <SignalServiceEnvelope> > RetrieveMessagesAsync(IMessagePipeCallback callback, CancellationToken?token = null) { if (token == null) { token = CancellationToken.None; } List <SignalServiceEnvelope> results = new List <SignalServiceEnvelope>(); List <SignalServiceEnvelopeEntity> entities = await socket.GetMessagesAsync(token); foreach (SignalServiceEnvelopeEntity entity in entities) { SignalServiceEnvelope envelope; if (entity.HasSource() && entity.SourceDevice > 0) { SignalServiceAddress address = new SignalServiceAddress(UuidUtil.ParseOrNull(entity.SourceUuid), entity.SourceE164); envelope = new SignalServiceEnvelope((int)entity.Type, address, (int)entity.SourceDevice, (int)entity.Timestamp, entity.Message, entity.Content, entity.ServerTimestamp, entity.ServerUuid); } else { envelope = new SignalServiceEnvelope((int)entity.Type, (int)entity.Timestamp, entity.Message, entity.Content, entity.ServerTimestamp, entity.ServerUuid); } await callback.OnMessageAsync(envelope); results.Add(envelope); if (envelope.HasUuid()) { await socket.AcknowledgeMessageAsync(envelope.GetUuid(), token); } else { await socket.AcknowledgeMessageAsync(entity.SourceE164 !, entity.Timestamp, token); } } return(results); }
public List<SignalServiceEnvelope> retrieveMessages(MessageReceivedCallback callback) { List<SignalServiceEnvelope> results = new List<SignalServiceEnvelope>(); List<SignalServiceEnvelopeEntity> entities = socket.getMessages(); foreach (SignalServiceEnvelopeEntity entity in entities) { SignalServiceEnvelope envelope = new SignalServiceEnvelope((int)entity.getType(), entity.getSource(), (int)entity.getSourceDevice(), entity.getRelay(), (int)entity.getTimestamp(), entity.getMessage(), entity.getContent()); callback.onMessage(envelope); results.Add(envelope); socket.acknowledgeMessage(entity.getSource(), entity.getTimestamp()); } return results; }
private void handleTextMessage(/*@NonNull MasterSecretUnion masterSecret,*/ SignalServiceEnvelope envelope, SignalServiceDataMessage message, May <long> smsMessageId) { var textMessageDatabase = DatabaseFactory.getTextMessageDatabase(); String body = message.getBody().HasValue ? message.getBody().ForceGetValue() : ""; IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo()); textMessage = new IncomingEncryptedMessage(textMessage, body); var messageAndThreadId = textMessageDatabase.InsertMessageInbox(textMessage); ToastHelper.NotifyNewMessage(messageAndThreadId.second(), DatabaseFactory.getDirectoryDatabase().GetForNumber(envelope.getSource()).Name, body); }
public void OnMessage(SignalServiceMessagePipeMessage message) { if (message is SignalServiceEnvelope) { SignalServiceEnvelope envelope = (SignalServiceEnvelope)message; List <SignalMessage> messages = new List <SignalMessage>(); if (envelope.isReceipt()) { SignalDBContext.IncreaseReceiptCountLocked(envelope, this); } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) { HandleMessage(envelope); } else { Debug.WriteLine("received message of unknown type " + envelope.getType() + " from " + envelope.getSource()); } } }
public async Task <List <SignalServiceEnvelope> > RetrieveMessages(CancellationToken token, IMessagePipeCallback callback) { List <SignalServiceEnvelope> results = new List <SignalServiceEnvelope>(); List <SignalServiceEnvelopeEntity> entities = await Socket.GetMessages(token); foreach (SignalServiceEnvelopeEntity entity in entities) { SignalServiceEnvelope envelope = new SignalServiceEnvelope((int)entity.Type, entity.Source, (int)entity.SourceDevice, entity.Relay, (int)entity.Timestamp, entity.Message, entity.Content); await callback.OnMessage(envelope); results.Add(envelope); await Socket.AcknowledgeMessage(token, entity.Source, entity.Timestamp); } return(results); }