/** * 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); } } }
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()); }
/** * 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); } }
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); }