use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class SmsReceiveJob method storeMessage.
private Optional<InsertResult> storeMessage(IncomingTextMessage message) throws MigrationPendingException {
MessageDatabase database = SignalDatabase.sms();
database.ensureMigration();
if (TextSecurePreferences.getNeedsSqlCipherMigration(context)) {
throw new MigrationPendingException();
}
if (message.isSecureMessage()) {
IncomingTextMessage placeholder = new IncomingTextMessage(message, "");
Optional<InsertResult> insertResult = database.insertMessageInbox(placeholder);
database.markAsLegacyVersion(insertResult.get().getMessageId());
return insertResult;
} else {
return database.insertMessageInbox(message);
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleCallOfferMessage.
private void handleCallOfferMessage(@NonNull SignalServiceContent content, @NonNull OfferMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Recipient senderRecipient) {
log(String.valueOf(content.getTimestamp()), "handleCallOfferMessage...");
if (smsMessageId.isPresent()) {
MessageDatabase database = SignalDatabase.sms();
database.markAsMissedCall(smsMessageId.get(), message.getType() == OfferMessage.Type.VIDEO_CALL);
} else {
RemotePeer remotePeer = new RemotePeer(senderRecipient.getId(), new CallId(message.getId()));
byte[] remoteIdentityKey = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecord(senderRecipient.getId()).transform(record -> record.getIdentityKey().serialize()).orNull();
ApplicationDependencies.getSignalCallManager().receivedOffer(new WebRtcData.CallMetadata(remotePeer, content.getSenderDevice()), new WebRtcData.OfferMetadata(message.getOpaque(), message.getSdp(), message.getType()), new WebRtcData.ReceivedOfferMetadata(remoteIdentityKey, content.getServerReceivedTimestamp(), content.getServerDeliveredTimestamp(), content.getCallMessage().get().isMultiRing()));
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleTextMessage.
@Nullable
private MessageId handleTextMessage(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId, @NonNull Optional<GroupId> groupId, @NonNull Recipient senderRecipient, @NonNull Recipient threadRecipient, long receivedTime) throws StorageFailedException {
log(message.getTimestamp(), "Text message.");
MessageDatabase database = SignalDatabase.sms();
String body = message.getBody().isPresent() ? message.getBody().get() : "";
if (message.getExpiresInSeconds() != threadRecipient.getExpiresInSeconds()) {
handleExpirationUpdate(content, message, Optional.absent(), groupId, senderRecipient, threadRecipient, receivedTime);
}
Optional<InsertResult> insertResult;
if (smsMessageId.isPresent() && !message.getGroupContext().isPresent()) {
insertResult = Optional.of(database.updateBundleMessageBody(smsMessageId.get(), body));
} else {
notifyTypingStoppedFromIncomingMessage(senderRecipient, threadRecipient, content.getSenderDevice());
IncomingTextMessage textMessage = new IncomingTextMessage(senderRecipient.getId(), content.getSenderDevice(), message.getTimestamp(), content.getServerReceivedTimestamp(), receivedTime, body, groupId, TimeUnit.SECONDS.toMillis(message.getExpiresInSeconds()), content.isNeedsReceipt(), content.getServerUuid());
textMessage = new IncomingEncryptedMessage(textMessage, body);
insertResult = database.insertMessageInbox(textMessage);
if (smsMessageId.isPresent())
database.deleteMessage(smsMessageId.get());
}
if (insertResult.isPresent()) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
return new MessageId(insertResult.get().getMessageId(), false);
} else {
return null;
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleSynchronizeSentEndSessionMessage.
private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message, long envelopeTimestamp) throws BadGroupIdException {
log(envelopeTimestamp, "Synchronize end session message.");
MessageDatabase database = SignalDatabase.sms();
Recipient recipient = getSyncMessageDestination(message);
OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, "", -1);
OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
if (!recipient.isGroup()) {
ApplicationDependencies.getProtocolStore().aci().deleteAllSessions(recipient.requireServiceId().toString());
SecurityEvent.broadcastSecurityUpdateEvent(context);
long messageId = database.insertMessageOutbox(threadId, outgoingEndSessionMessage, false, message.getTimestamp(), null);
database.markAsSent(messageId, true);
SignalDatabase.threads().update(threadId, true);
}
return threadId;
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleEndSessionMessage.
@Nullable
private MessageId handleEndSessionMessage(@NonNull SignalServiceContent content, @NonNull Optional<Long> smsMessageId, @NonNull Recipient senderRecipient) {
log(content.getTimestamp(), "End session message.");
MessageDatabase smsDatabase = SignalDatabase.sms();
IncomingTextMessage incomingTextMessage = new IncomingTextMessage(senderRecipient.getId(), content.getSenderDevice(), content.getTimestamp(), content.getServerReceivedTimestamp(), System.currentTimeMillis(), "", Optional.absent(), 0, content.isNeedsReceipt(), content.getServerUuid());
Optional<InsertResult> insertResult;
if (!smsMessageId.isPresent()) {
IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
insertResult = smsDatabase.insertMessageInbox(incomingEndSessionMessage);
} else {
smsDatabase.markAsEndSession(smsMessageId.get());
insertResult = Optional.of(new InsertResult(smsMessageId.get(), smsDatabase.getThreadIdForMessage(smsMessageId.get())));
}
if (insertResult.isPresent()) {
ApplicationDependencies.getProtocolStore().aci().deleteAllSessions(content.getSender().getIdentifier());
SecurityEvent.broadcastSecurityUpdateEvent(context);
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
return new MessageId(insertResult.get().getMessageId(), true);
} else {
return null;
}
}
Aggregations