use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by WhisperSystems.
the class MessageSender method send.
public static long send(final Context context, final OutgoingTextMessage message, final long threadId, final boolean forceSms, @Nullable final String metricId, final SmsDatabase.InsertListener insertListener) {
Log.i(TAG, "Sending text message to " + message.getRecipient().getId() + ", thread: " + threadId);
MessageDatabase database = SignalDatabase.sms();
Recipient recipient = message.getRecipient();
boolean keyExchange = message.isKeyExchange();
long allocatedThreadId = SignalDatabase.threads().getOrCreateValidThreadId(recipient, threadId);
long messageId = database.insertMessageOutbox(allocatedThreadId, applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), forceSms, System.currentTimeMillis(), insertListener);
SignalLocalMetrics.IndividualMessageSend.onInsertedIntoDatabase(messageId, metricId);
sendTextMessage(context, recipient, forceSms, keyExchange, messageId);
onMessageSent();
SignalDatabase.threads().update(threadId, true);
return allocatedThreadId;
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by WhisperSystems.
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 WhisperSystems.
the class MessageContentProcessor method handleExpirationUpdate.
@Nullable
private MessageId handleExpirationUpdate(@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(content.getTimestamp(), "Expiration update.");
if (groupId.isPresent() && groupId.get().isV2()) {
warn(String.valueOf(content.getTimestamp()), "Expiration update received for GV2. Ignoring.");
return null;
}
int expiresInSeconds = message.getExpiresInSeconds();
Optional<SignalServiceGroupContext> groupContext = message.getGroupContext();
if (threadRecipient.getExpiresInSeconds() == expiresInSeconds) {
log(String.valueOf(content.getTimestamp()), "No change in message expiry for group. Ignoring.");
return null;
}
try {
MessageDatabase database = SignalDatabase.mms();
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(senderRecipient.getId(), content.getTimestamp(), content.getServerReceivedTimestamp(), receivedTime, -1, expiresInSeconds * 1000L, true, false, content.isNeedsReceipt(), Optional.absent(), groupContext, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), content.getServerUuid());
Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
SignalDatabase.recipients().setExpireMessages(threadRecipient.getId(), expiresInSeconds);
if (smsMessageId.isPresent()) {
SignalDatabase.sms().deleteMessage(smsMessageId.get());
}
if (insertResult.isPresent()) {
return new MessageId(insertResult.get().getMessageId(), true);
}
} catch (MmsException e) {
throw new StorageFailedException(e, content.getSender().getIdentifier(), content.getSenderDevice());
}
return null;
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handleSynchronizeSentTextMessage.
private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message, long envelopeTimestamp) throws MmsException, BadGroupIdException {
log(envelopeTimestamp, "Synchronize sent text message for " + message.getTimestamp());
Recipient recipient = getSyncMessageDestination(message);
String body = message.getMessage().getBody().or("");
long expiresInMillis = TimeUnit.SECONDS.toMillis(message.getMessage().getExpiresInSeconds());
if (recipient.getExpiresInSeconds() != message.getMessage().getExpiresInSeconds()) {
handleSynchronizeSentExpirationUpdate(message);
}
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
boolean isGroup = recipient.isGroup();
MessageDatabase database;
long messageId;
if (isGroup) {
OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, false, ThreadDatabase.DistributionTypes.DEFAULT, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);
messageId = SignalDatabase.mms().insertMessageOutbox(outgoingMediaMessage, threadId, false, GroupReceiptDatabase.STATUS_UNKNOWN, null);
database = SignalDatabase.mms();
updateGroupReceiptStatus(message, messageId, recipient.requireGroupId());
} else {
OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);
messageId = SignalDatabase.sms().insertMessageOutbox(threadId, outgoingTextMessage, false, message.getTimestamp(), null);
database = SignalDatabase.sms();
database.markUnidentified(messageId, isUnidentified(message, recipient));
SignalDatabase.threads().update(threadId, true);
}
database.markAsSent(messageId, true);
if (expiresInMillis > 0) {
database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
ApplicationDependencies.getExpiringMessageManager().scheduleDeletion(messageId, isGroup, message.getExpirationStartTimestamp(), expiresInMillis);
}
if (recipient.isSelf()) {
SyncMessageId id = new SyncMessageId(recipient.getId(), message.getTimestamp());
SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
}
return threadId;
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by WhisperSystems.
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;
}
}
Aggregations