use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
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 signalapp.
the class MessageSender method sendRemoteDelete.
public static void sendRemoteDelete(@NonNull Context context, long messageId, boolean isMms) {
MessageDatabase db = isMms ? SignalDatabase.mms() : SignalDatabase.sms();
db.markAsRemoteDelete(messageId);
db.markAsSending(messageId);
try {
ApplicationDependencies.getJobManager().add(RemoteDeleteSendJob.create(context, messageId, isMms));
onMessageSent();
} catch (NoSuchMessageException e) {
Log.w(TAG, "[sendRemoteDelete] Could not find message! Ignoring.");
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class LegacyMigrationJob method schedulePendingIncomingParts.
private void schedulePendingIncomingParts(Context context) {
final AttachmentDatabase attachmentDb = SignalDatabase.attachments();
final MessageDatabase mmsDb = SignalDatabase.mms();
final List<DatabaseAttachment> pendingAttachments = SignalDatabase.attachments().getPendingAttachments();
Log.i(TAG, pendingAttachments.size() + " pending parts.");
for (DatabaseAttachment attachment : pendingAttachments) {
final Reader reader = MmsDatabase.readerFor(mmsDb.getMessageCursor(attachment.getMmsId()));
final MessageRecord record = reader.getNext();
if (attachment.hasData()) {
Log.i(TAG, "corrected a pending media part " + attachment.getAttachmentId() + "that already had data.");
attachmentDb.setTransferState(attachment.getMmsId(), attachment.getAttachmentId(), AttachmentDatabase.TRANSFER_PROGRESS_DONE);
} else if (record != null && !record.isOutgoing() && record.isPush()) {
Log.i(TAG, "queuing new attachment download job for incoming push part " + attachment.getAttachmentId() + ".");
ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(attachment.getMmsId(), attachment.getAttachmentId(), false));
}
reader.close();
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class ConversationDataSource method load.
@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
stopwatch.split("message");
try {
if (record != null) {
List<Mention> mentions;
if (messageId.isMms()) {
mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
} else {
mentions = Collections.emptyList();
}
stopwatch.split("mentions");
List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
record = ReactionHelper.recordWithReactions(record, reactions);
stopwatch.split("reactions");
if (messageId.isMms()) {
List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
if (attachments.size() > 0) {
record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
}
}
stopwatch.split("attachments");
return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
} else {
return null;
}
} finally {
stopwatch.stop(TAG);
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class RemoteDeleteSendJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
MessageDatabase db;
MessageRecord message;
if (isMms) {
db = SignalDatabase.mms();
message = SignalDatabase.mms().getMessageRecord(messageId);
} else {
db = SignalDatabase.sms();
message = SignalDatabase.sms().getSmsMessage(messageId);
}
long targetSentTimestamp = message.getDateSent();
Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(message.getThreadId());
if (conversationRecipient == null) {
throw new AssertionError("We have a message, but couldn't find the thread!");
}
if (!message.isOutgoing()) {
throw new IllegalStateException("Cannot delete a message that isn't yours!");
}
List<Recipient> destinations = Stream.of(recipients).map(Recipient::resolved).toList();
List<Recipient> completions = deliver(conversationRecipient, destinations, targetSentTimestamp);
for (Recipient completion : completions) {
recipients.remove(completion.getId());
}
Log.i(TAG, "Completed now: " + completions.size() + ", Remaining: " + recipients.size());
if (recipients.isEmpty()) {
db.markAsSent(messageId, true);
} else {
Log.w(TAG, "Still need to send to " + recipients.size() + " recipients. Retrying.");
throw new RetryLaterException();
}
}
Aggregations