mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Dont requery attachments and add all jobs at once.
This commit is contained in:
@@ -12,7 +12,6 @@ import org.signal.core.util.toOptional
|
||||
import org.signal.libsignal.zkgroup.groups.GroupSecretParams
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation
|
||||
import org.thoughtcrime.securesms.attachments.Attachment
|
||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment
|
||||
import org.thoughtcrime.securesms.attachments.PointerAttachment
|
||||
import org.thoughtcrime.securesms.attachments.TombstoneAttachment
|
||||
import org.thoughtcrime.securesms.attachments.UriAttachment
|
||||
@@ -875,14 +874,19 @@ object DataMessageProcessor {
|
||||
|
||||
return if (insertResult != null) {
|
||||
SignalDatabase.runPostSuccessfulTransaction {
|
||||
val allAttachments = SignalDatabase.attachments.getAttachmentsForMessage(insertResult.messageId)
|
||||
val stickerAttachments = allAttachments.filter { it.isSticker }.toList()
|
||||
val otherAttachments = allAttachments.filterNot { it.isSticker }.toList()
|
||||
|
||||
forceStickerDownloadIfNecessary(context, insertResult.messageId, stickerAttachments)
|
||||
|
||||
for (attachment in otherAttachments) {
|
||||
ApplicationDependencies.getJobManager().add(AttachmentDownloadJob(insertResult.messageId, attachment.attachmentId, false))
|
||||
if (insertResult.insertedAttachments != null) {
|
||||
val downloadJobs: List<AttachmentDownloadJob> = insertResult.insertedAttachments.mapNotNull { (attachment, attachmentId) ->
|
||||
if (attachment.isSticker) {
|
||||
if (attachment.transferState != AttachmentTable.TRANSFER_PROGRESS_DONE) {
|
||||
AttachmentDownloadJob(insertResult.messageId, attachmentId, true)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
AttachmentDownloadJob(insertResult.messageId, attachmentId, false)
|
||||
}
|
||||
}
|
||||
ApplicationDependencies.getJobManager().addAll(downloadJobs)
|
||||
}
|
||||
|
||||
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(insertResult.threadId))
|
||||
@@ -990,24 +994,6 @@ object DataMessageProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
fun forceStickerDownloadIfNecessary(context: Context, messageId: Long, stickerAttachments: List<DatabaseAttachment>) {
|
||||
if (stickerAttachments.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val stickerAttachment = stickerAttachments[0]
|
||||
if (stickerAttachment.transferState != AttachmentTable.TRANSFER_PROGRESS_DONE) {
|
||||
val downloadJob = AttachmentDownloadJob(messageId, stickerAttachment.attachmentId, true)
|
||||
try {
|
||||
downloadJob.setContext(context)
|
||||
downloadJob.doWork()
|
||||
} catch (e: Exception) {
|
||||
warn("Failed to download sticker inline. Scheduling.")
|
||||
ApplicationDependencies.getJobManager().add(downloadJob)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun insertPlaceholder(sender: RecipientId, senderDevice: Int, timestamp: Long, groupId: GroupId?): InsertResult? {
|
||||
val textMessage = IncomingTextMessage(
|
||||
sender,
|
||||
|
||||
@@ -794,7 +794,7 @@ public class MessageContentProcessor {
|
||||
insertResult = smsDatabase.insertMessageInbox(incomingEndSessionMessage);
|
||||
} else {
|
||||
smsDatabase.markAsEndSession(smsMessageId.get());
|
||||
insertResult = Optional.of(new InsertResult(smsMessageId.get(), smsDatabase.getThreadIdForMessage(smsMessageId.get())));
|
||||
insertResult = Optional.of(new InsertResult(smsMessageId.get(), smsDatabase.getThreadIdForMessage(smsMessageId.get()), null));
|
||||
}
|
||||
|
||||
if (insertResult.isPresent()) {
|
||||
|
||||
@@ -771,7 +771,6 @@ object SyncMessageProcessor {
|
||||
val threadId = SignalDatabase.threads.getOrCreateThreadIdFor(recipient)
|
||||
val messageId: Long
|
||||
val attachments: List<DatabaseAttachment>
|
||||
val stickerAttachments: List<DatabaseAttachment>
|
||||
|
||||
SignalDatabase.messages.beginTransaction()
|
||||
try {
|
||||
@@ -785,9 +784,7 @@ object SyncMessageProcessor {
|
||||
|
||||
SignalDatabase.messages.markAsSent(messageId, true)
|
||||
|
||||
val allAttachments = SignalDatabase.attachments.getAttachmentsForMessage(messageId)
|
||||
stickerAttachments = allAttachments.filter { it.isSticker }
|
||||
attachments = allAttachments.filterNot { it.isSticker }
|
||||
attachments = SignalDatabase.attachments.getAttachmentsForMessage(messageId)
|
||||
|
||||
if (sent.message.expireTimer > 0) {
|
||||
SignalDatabase.messages.markExpireStarted(messageId, sent.expirationStartTimestamp)
|
||||
@@ -803,11 +800,10 @@ object SyncMessageProcessor {
|
||||
SignalDatabase.messages.endTransaction()
|
||||
}
|
||||
SignalDatabase.runPostSuccessfulTransaction {
|
||||
val downloadJobs: List<AttachmentDownloadJob> = attachments.map { AttachmentDownloadJob(messageId, it.attachmentId, false) }
|
||||
for (attachment in attachments) {
|
||||
ApplicationDependencies.getJobManager().add(AttachmentDownloadJob(messageId, attachment.attachmentId, false))
|
||||
ApplicationDependencies.getJobManager().addAll(downloadJobs)
|
||||
}
|
||||
|
||||
DataMessageProcessor.forceStickerDownloadIfNecessary(context, messageId, stickerAttachments)
|
||||
}
|
||||
|
||||
return threadId
|
||||
|
||||
Reference in New Issue
Block a user