public TextSecureContent(TextSecureDataMessage message)
 {
     this.message = message == null ? May<TextSecureDataMessage>.NoValue : new May<TextSecureDataMessage>(message);
     this.synchronizeMessage = May<TextSecureSyncMessage>.NoValue;
 }
        private async Task<byte[]> createMessageContent(TextSecureDataMessage message)// throws IOException
        {
            DataMessage.Builder builder = DataMessage.CreateBuilder();
            /*List<AttachmentPointer> pointers = createAttachmentPointers(message.getAttachments());

            if (!pointers.Any()) // TODO:check
            {
                builder.AddRangeAttachments(pointers);
            }*/

            if (message.getBody().HasValue)
            {
                builder.SetBody(message.getBody().ForceGetValue());
            }

            if (message.getGroupInfo().HasValue)
            {
                builder.SetGroup(createGroupContent(message.getGroupInfo().ForceGetValue()));
            }

            if (message.isEndSession())
            {
                builder.SetFlags((uint)DataMessage.Types.Flags.END_SESSION);
            }

            return builder.Build().ToByteArray();
        }
        /**
         * Send a message to a single recipient.
         *
         * @param recipient The message's destination.
         * @param message The message.
         * @throws UntrustedIdentityException
         * @throws IOException
         */
        public async void sendMessage(TextSecureAddress recipient, TextSecureDataMessage message)
        {
            byte[] content = await createMessageContent(message);
            ulong timestamp = message.getTimestamp();
            SendMessageResponse response = sendMessage(recipient, timestamp, content, true);

            if (response != null && response.getNeedsSync())
            {
                byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, new May<TextSecureAddress>(recipient), timestamp);
                sendMessage(localAddress, timestamp, syncMessage, false);
            }

            if (message.isEndSession())
            {
                store.DeleteAllSessions(recipient.getNumber());

                if (eventListener.HasValue)
                {
                    eventListener.ForceGetValue().onSecurityEvent(recipient);
                }
            }
        }
        /**
         * Send a message to a group.
         *
         * @param recipients The group members.
         * @param message The group message.
         * @throws IOException
         * @throws EncapsulatedExceptions
         */
        public async void sendMessage(List<TextSecureAddress> recipients, TextSecureDataMessage message)
        {
            byte[] content = await createMessageContent(message);
            ulong timestamp = message.getTimestamp();
            SendMessageResponse response = sendMessage(recipients, timestamp, content, true);

            try
            {
                if (response != null && response.getNeedsSync())
                {
                    byte[] syncMessage = createMultiDeviceSentTranscriptContent(content, May<TextSecureAddress>.NoValue, timestamp);
                    sendMessage(localAddress, timestamp, syncMessage, false);
                }
            }
            catch (UntrustedIdentityException e)
            {
                throw new EncapsulatedExceptions(e);
            }
        }
Exemplo n.º 5
0
        private void handleTextMessage(/*@NonNull MasterSecretUnion masterSecret,*/
                                       TextSecureEnvelope envelope,
                                       TextSecureDataMessage 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());
        }
Exemplo n.º 6
0
        private void handleMediaMessage(TextSecureEnvelope envelope, TextSecureDataMessage 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);*/
        }
Exemplo n.º 7
0
        private void handleGroupMessage(TextSecureEnvelope envelope, TextSecureDataMessage 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());
            }
        }
Exemplo n.º 8
0
        private void handleEndSessionMessage(TextSecureEnvelope envelope,
                                             TextSecureDataMessage message,
                                             May<long> smsMessageId)
        {
            var smsDatabase = DatabaseFactory.getTextMessageDatabase();//getEncryptingSmsDatabase(context);
            var incomingTextMessage = new IncomingTextMessage(envelope.getSource(),
                                                                                envelope.getSourceDevice(),
                                                                                message.getTimestamp(),
                                                                                "", May<TextSecureGroup>.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);
        }