private void handleMessage(TextSecureEnvelope 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())); }
public long Insert(TextSecureEnvelope envelope) { // TODO check if exists var push = new Push() { Type = envelope.getType(), Source = envelope.getSource(), DeviceId = envelope.getSourceDevice(), LegacyMessage = envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "", Content = envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "", Timestamp = TimeUtil.GetDateTime(envelope.getTimestamp()) }; try { conn.Insert(push); } catch(Exception e) { Debug.WriteLine(e.Message); } return push.PushId; }
private TextSecureDataMessage createTextSecureMessage(TextSecureEnvelope envelope, DataMessage content) { TextSecureGroup groupInfo = createGroupInfo(envelope, content); LinkedList<TextSecureAttachment> attachments = new LinkedList<TextSecureAttachment>(); bool endSession = ((content.Flags & (uint)DataMessage.Types.Flags.END_SESSION) != 0); foreach (AttachmentPointer pointer in content.AttachmentsList) { attachments.AddLast(new TextSecureAttachmentPointer(pointer.Id, pointer.ContentType, pointer.Key.ToByteArray(), envelope.getRelay(), pointer.HasSize ? new May<uint>(pointer.Size) : May<uint>.NoValue, pointer.HasThumbnail ? new May<byte[]>(pointer.Thumbnail.ToByteArray()) : May<byte[]>.NoValue)); } return new TextSecureDataMessage(envelope.getTimestamp(), groupInfo, attachments, content.Body, endSession); }
private Pair<long, long> insertPlaceholder(TextSecureEnvelope envelope) { var database = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context); IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), "", May<TextSecureGroup>.NoValue); textMessage = new IncomingEncryptedMessage(textMessage, ""); return database.InsertMessageInbox(textMessage); }
private void handleUntrustedIdentityMessage(TextSecureEnvelope envelope, May<long> smsMessageId) { try { var database = DatabaseFactory.getTextMessageDatabase(); //getEncryptingSmsDatabase(context); Recipients recipients = RecipientFactory.getRecipientsFromString(envelope.getSource(), false); long recipientId = recipients.getPrimaryRecipient().getRecipientId(); PreKeyWhisperMessage whisperMessage = new PreKeyWhisperMessage(envelope.getLegacyMessage()); IdentityKey identityKey = whisperMessage.getIdentityKey(); String encoded = Base64.encodeBytes(envelope.getLegacyMessage()); IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), encoded, May<TextSecureGroup>.NoValue); if (!smsMessageId.HasValue) { IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded); Pair<long, long> messageAndThreadId = database.InsertMessageInbox(bundleMessage); database.SetMismatchedIdentity(messageAndThreadId.first(), recipientId, identityKey); //MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), messageAndThreadId.second); } else { var messageId = smsMessageId.ForceGetValue(); database.UpdateMessageBody(messageId, encoded); database.MarkAsPreKeyBundle(messageId); database.SetMismatchedIdentity(messageId, recipientId, identityKey); } } catch (InvalidMessageException e) { throw new InvalidOperationException(e.Message); } catch (InvalidVersionException e) { throw new InvalidOperationException(e.Message); } }
private void handleReceipt(TextSecureEnvelope envelope) { Log.Debug($"Received receipt: (XXXXX, {envelope.getTimestamp()})"); DatabaseFactory.getMessageDatabase().incrementDeliveryReceiptCount(envelope.getSource(), (long)envelope.getTimestamp()); }