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 OutgoingMediaMessage message, final long threadId, final boolean forceSms, @Nullable final String metricId, final SmsDatabase.InsertListener insertListener) {
Log.i(TAG, "Sending media message to " + message.getRecipient().getId() + ", thread: " + threadId);
try {
ThreadDatabase threadDatabase = SignalDatabase.threads();
MessageDatabase database = SignalDatabase.mms();
long allocatedThreadId = threadDatabase.getOrCreateValidThreadId(message.getRecipient(), threadId, message.getDistributionType());
Recipient recipient = message.getRecipient();
long messageId = database.insertMessageOutbox(applyUniversalExpireTimerIfNecessary(context, recipient, message, allocatedThreadId), allocatedThreadId, forceSms, insertListener);
if (message.getRecipient().isGroup() && message.getAttachments().isEmpty() && message.getLinkPreviews().isEmpty() && message.getSharedContacts().isEmpty()) {
SignalLocalMetrics.GroupMessageSend.onInsertedIntoDatabase(messageId, metricId);
} else {
SignalLocalMetrics.GroupMessageSend.cancel(metricId);
}
sendMediaMessage(context, recipient, forceSms, messageId, Collections.emptyList());
onMessageSent();
threadDatabase.update(threadId, true);
return allocatedThreadId;
} catch (MmsException e) {
Log.w(TAG, e);
return threadId;
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class IdentityUtil method markIdentityVerified.
public static void markIdentityVerified(Context context, Recipient recipient, boolean verified, boolean remote) {
long time = System.currentTimeMillis();
MessageDatabase smsDatabase = SignalDatabase.sms();
GroupDatabase groupDatabase = SignalDatabase.groups();
try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
GroupDatabase.GroupRecord groupRecord;
while ((groupRecord = reader.getNext()) != null) {
if (groupRecord.getMembers().contains(recipient.getId()) && groupRecord.isActive() && !groupRecord.isMms()) {
if (remote) {
IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.of(groupRecord.getId()), 0, false, null);
if (verified)
incoming = new IncomingIdentityVerifiedMessage(incoming);
else
incoming = new IncomingIdentityDefaultMessage(incoming);
smsDatabase.insertMessageInbox(incoming);
} else {
RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupRecord.getId());
Recipient groupRecipient = Recipient.resolved(recipientId);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
OutgoingTextMessage outgoing;
if (verified)
outgoing = new OutgoingIdentityVerifiedMessage(recipient);
else
outgoing = new OutgoingIdentityDefaultMessage(recipient);
SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
SignalDatabase.threads().update(threadId, true);
}
}
}
}
if (remote) {
IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.absent(), 0, false, null);
if (verified)
incoming = new IncomingIdentityVerifiedMessage(incoming);
else
incoming = new IncomingIdentityDefaultMessage(incoming);
smsDatabase.insertMessageInbox(incoming);
} else {
OutgoingTextMessage outgoing;
if (verified)
outgoing = new OutgoingIdentityVerifiedMessage(recipient);
else
outgoing = new OutgoingIdentityDefaultMessage(recipient);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
Log.i(TAG, "Inserting verified outbox...");
SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
SignalDatabase.threads().update(threadId, true);
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class IdentityUtil method markIdentityUpdate.
public static void markIdentityUpdate(@NonNull Context context, @NonNull RecipientId recipientId) {
long time = System.currentTimeMillis();
MessageDatabase smsDatabase = SignalDatabase.sms();
GroupDatabase groupDatabase = SignalDatabase.groups();
try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
GroupDatabase.GroupRecord groupRecord;
while ((groupRecord = reader.getNext()) != null) {
if (groupRecord.getMembers().contains(recipientId) && groupRecord.isActive()) {
IncomingTextMessage incoming = new IncomingTextMessage(recipientId, 1, time, time, time, null, Optional.of(groupRecord.getId()), 0, false, null);
IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
smsDatabase.insertMessageInbox(groupUpdate);
}
}
}
IncomingTextMessage incoming = new IncomingTextMessage(recipientId, 1, time, -1, time, null, Optional.absent(), 0, false, null);
IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(individualUpdate);
if (insertResult.isPresent()) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleSynchronizeSentMediaMessage.
private long handleSynchronizeSentMediaMessage(@NonNull SentTranscriptMessage message, long envelopeTimestamp) throws MmsException, BadGroupIdException {
log(envelopeTimestamp, "Synchronize sent media message for " + message.getTimestamp());
MessageDatabase database = SignalDatabase.mms();
Recipient recipients = getSyncMessageDestination(message);
Optional<QuoteModel> quote = getValidatedQuote(message.getMessage().getQuote());
Optional<Attachment> sticker = getStickerAttachment(message.getMessage().getSticker());
Optional<List<Contact>> sharedContacts = getContacts(message.getMessage().getSharedContacts());
Optional<List<LinkPreview>> previews = getLinkPreviews(message.getMessage().getPreviews(), message.getMessage().getBody().or(""));
Optional<List<Mention>> mentions = getMentions(message.getMessage().getMentions());
boolean viewOnce = message.getMessage().isViewOnce();
List<Attachment> syncAttachments = viewOnce ? Collections.singletonList(new TombstoneAttachment(MediaUtil.VIEW_ONCE, false)) : PointerAttachment.forPointers(message.getMessage().getAttachments());
if (sticker.isPresent()) {
syncAttachments.add(sticker.get());
}
OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(), syncAttachments, message.getTimestamp(), -1, TimeUnit.SECONDS.toMillis(message.getMessage().getExpiresInSeconds()), viewOnce, ThreadDatabase.DistributionTypes.DEFAULT, quote.orNull(), sharedContacts.or(Collections.emptyList()), previews.or(Collections.emptyList()), mentions.or(Collections.emptyList()), Collections.emptySet(), Collections.emptySet());
mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
if (recipients.getExpiresInSeconds() != message.getMessage().getExpiresInSeconds()) {
handleSynchronizeSentExpirationUpdate(message);
}
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipients);
long messageId;
List<DatabaseAttachment> attachments;
List<DatabaseAttachment> stickerAttachments;
database.beginTransaction();
try {
messageId = database.insertMessageOutbox(mediaMessage, threadId, false, GroupReceiptDatabase.STATUS_UNKNOWN, null);
if (recipients.isGroup()) {
updateGroupReceiptStatus(message, messageId, recipients.requireGroupId());
} else {
database.markUnidentified(messageId, isUnidentified(message, recipients));
}
database.markAsSent(messageId, true);
List<DatabaseAttachment> allAttachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId);
stickerAttachments = Stream.of(allAttachments).filter(Attachment::isSticker).toList();
attachments = Stream.of(allAttachments).filterNot(Attachment::isSticker).toList();
if (message.getMessage().getExpiresInSeconds() > 0) {
database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
ApplicationDependencies.getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpirationStartTimestamp(), TimeUnit.SECONDS.toMillis(message.getMessage().getExpiresInSeconds()));
}
if (recipients.isSelf()) {
SyncMessageId id = new SyncMessageId(recipients.getId(), message.getTimestamp());
SignalDatabase.mmsSms().incrementDeliveryReceiptCount(id, System.currentTimeMillis());
SignalDatabase.mmsSms().incrementReadReceiptCount(id, System.currentTimeMillis());
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
for (DatabaseAttachment attachment : attachments) {
ApplicationDependencies.getJobManager().add(new AttachmentDownloadJob(messageId, attachment.getAttachmentId(), false));
}
forceStickerDownloadIfNecessary(messageId, stickerAttachments);
return threadId;
}
use of org.thoughtcrime.securesms.database.MessageDatabase in project Signal-Android by signalapp.
the class MessageContentProcessor method handleUnsupportedDataMessage.
private void handleUnsupportedDataMessage(@NonNull String sender, int senderDevice, @NonNull Optional<GroupId> groupId, long timestamp, @NonNull Optional<Long> smsMessageId) {
log(timestamp, "Unsupported data message.");
MessageDatabase smsDatabase = SignalDatabase.sms();
if (!smsMessageId.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp, groupId);
if (insertResult.isPresent()) {
smsDatabase.markAsUnsupportedProtocolVersion(insertResult.get().getMessageId());
ApplicationDependencies.getMessageNotifier().updateNotification(context, insertResult.get().getThreadId());
}
} else {
smsDatabase.markAsNoSession(smsMessageId.get());
}
}
Aggregations